Ajax / Asynchronous - GridView asp.net (webforms)

Jose Sebastian Garcia 1 Reputation point
2022-09-12T15:51:16.283+00:00

Hello! I hope you are doing good! I am writing to you because surely you have already come across this need and I do not find much information about it by googling, what is more, I already have a laboratory, a custom control that solves the need, but I feel that I am reinventing the wheel so here is my query.

Giving maintenance to a legacy, I came across the need to asynchronously load a grid within a webform page (gridview grid or grid made with repeater), in principle for simplicity I prefer to have a separate custom control that I can reuse but I want to be able to use it both from code behind and from javascript because there are several cases to consider.

I would be grateful if you would tell me if you already know of something existing for this or if I continue with what I am putting together.

EDIT:
Objective: It doesn't matter how long the grid takes, I'm only interested in the page loading quickly, with the restriction of not being able to place indexes in databases.

Thank you very much,
best regards,
Sebastian

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,254 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,238 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Albert Kallal 4,651 Reputation points
    2022-09-16T16:07:04.427+00:00

    Well, ok, several issues here.

    You can (could) load the grid inside of a up-date panel. And you could make this up-date panel part of the user control.

    it not clear if you need the gridview (gv) to load asynchronous to speed up page load time, or for some other reason?

    Often the issue is not load speed of the gv, but of course wanting to eliminate the post-back. (since that will often say cause the browser to scroll - and thus using + working + selecting a item from a grid, then you lose your position on the page)

    Loading a grid with some asynchronous method WILL NOT make the grid load faster.

    However, you could say have the web page load first, and THEN have the gv load + display. So, the user will perceive a faster load time, since the page was displaying before the grid did.

    However, time to load a gv should be VERY little. Even if the database has 1 million rows, your gv only going to display say 20 or 40 rows, and thus will and still should load instant.

    So, if the gv load time is slow? Then fix that issue, and then all other issues go away

    Edit:

    Ok, so the post 100% realizes the performance should be fixed - but the following should work well

    Just remember to give that poor server a hug, ok? ;-)

    so, add the script manager, and then drop in a update panel, then content template, and then YOUR gv inside.

    Like this:

    242103-image.png

    Note careful how we ALSO placed a button in the panel - when clicked on it will load up the gv. (we use client side code to click this button).

    Also, I dropped in a progress panel. These are nice, since you don't have to write extra client side JavaScript to show/hide some kind of message
    (or in my case a spinner gif).

    My button code to load gv is this - not really all that important

    242104-image.png

    Note for above - REMOVE that fake delay i have - this was just for testing to slow down the gv for this example.

    Ok, last but not least, we add a wee bit of js code - right at the bottom of the web page - (right before form tag, or content tag (if a page inside master page).

    So then this:

    242183-image.png

    so, like all page loads with code behind, you ONLY EVER load up those controls inside of a IsPostBack = false right?
    (since if you don't, then any button click or anything else you do on that page will trigger a re-load of the gv).

    So, above works very nice. The page will render, display, and then the gv will load.

    Regards,
    Albert D. Kallal (Access MVP 2003-2017)
    Edmonton, Alberta Canada