4

When my page loads up, I need to immediately initiate a a data pull in one of the page's user controls for it to populate some search results that display in a grid in that user control. The query to pull those search results can take quite a bit of time (8-10 seconds).

My goal is to make an Ajax request to only update the part of the page containing the user control so that the user can freely interact with other elements on the page while the expensive user control loads it's own data by itself.

In my current approach, the user cannot interact with any elements on the page while that control is loading. When they click on a button for example elsewhere on the page, the Page_Load() for the button click's postback is not reached until the long-running ajax request is finished. It seems that the other Ajax requests are waiting in line behind the long running one.

Here's my approach (Telerik Controls Used for Ajax):

I have a RadAjaxPanel that has a hidden button that will cause the Ajax postback. This button is clicked via Javascript when the page loads. In the click handler for the button there is code to load the user control into the ContentPlaceHolderControl and load the control's data

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="LoadingPanel1">
                <asp:PlaceHolder runat="server" ID="PlaceHolderControl">

                      <!-- user control loaded here -->

                    <telerik:RadButton ID="btnRADAjax" runat="server" Style="visibility: hidden;"></telerik:RadButton>

                </asp:PlaceHolder>

The Javascript that invokes button to do the Ajax PostBack:

  function DoAjaxPostBack() {


            var interval = setInterval(function() 
                {
                    if(document.readyState === 'complete') 
                    {
                        var argmnt='';
                         var ajaxManager =  $find("<%=RadAjaxManager.GetCurrent(Page).ClientID %>");
                        ajaxManager.ajaxRequestWithTarget('<%= btnRADAjax.UniqueID %>', argmnt);

                        clearInterval(interval);
                    }
                 },100)
       }

On pageLoad:

 If Not IsPostBack Then
            RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "1", "DoAjaxPostBack('');", True)
 End If

Is this a sound approach and there is just no way to get the Ajax Requests from blocking each other? Or is there another approach to get the long-running request to run separately in it's own world without it interfering with the responsiveness of the page it lives on? I'm considering trying an IFrame.

Thanks!

unnknown
  • 1,715
  • 2
  • 19
  • 37

2 Answers2

2

I don't know how RadAjaxPanel works but I think you are hitting the Session Lock system of ASP.NET.

By default, you can't run two concurrent request with the same session in ASP.NET. So your long request that takes 8-10 seconds will block all subsequent requests until it's finished. That's why the Page_Load() is not reached until the first request is completed.

You can try tweaking the EnableSessionState attribute of your page to disable the lock.

For more information see this post :

I just discovered why all ASP.Net websites are slow, and I am trying to work out what to do about it

Community
  • 1
  • 1
cpaulus
  • 284
  • 1
  • 14
1

Invoke a browser Dev Tools -> Network tab (usually using the F12 key) and check requests with the "Pending" (or something similar) state. If there is any (a possible long-running) request, it is likely that this issue is caused by blocking concurrent requests when the Session state is enabled. Check the following resources to learn more on why this may occur and related internal ASP.NET details:

Why can’t I execute two requests from the same session simultaneously for an ASP.NET application?

ASP.NET Session State Overview - Concurrent Requests and Session State

I just discovered why all ASP.Net websites are slow, and I am trying to work out what to do about it

If so, it may be necessary to disable the Session state at this page:

<%@ Page ... EnableSessionState="False" %>

or the entire application level:

<system.web>
    <sessionState mode="Off"></sessionState>
</system.web>

and either use another state (State Overview - Alternatives) or another approach for this purpose.

Community
  • 1
  • 1
Mikhail
  • 9,186
  • 4
  • 33
  • 49