Dynamically loaded controls and ajax: how to prevent reloading the controls when not using page.IsPostback

Last post 10-04-2007 3:47 AM by Jin-Yu Yin - MSFT. 1 replies.

Sort Posts:

  • Dynamically loaded controls and ajax: how to prevent reloading the controls when not using page.IsPostback

    09-28-2007, 6:09 AM
    • Loading...
    • jkey
    • Joined on 04-03-2006, 9:23 AM
    • Posts 32

    I thought I should share this, as I have not come across much about it in any of the forums.

    I have been using ajax update panels extensively, but have often been disappointed with their performance when used in pages that loads controls dynamically. In my case, I had several dynamic controls placed in the master page that themselves relied on ajax functionality. On regular postbacks, these controls need to be regenerated during the PageInit phase, so the option to wrap the initialization in a if not page.ispostback is not really there to prevent the code from running when it is not supposed to. The implication is a great deal of additional useless work on the server during async postbacks.

    During an asynch postback would most of these controls not have to be re-initiated at all. By wrapping the PageInit/PageLoad routine in the following construct, I can achieve the same effect as with the page.ispostback construct:

    If Not ScriptManager.GetCurrent(Me.Page).IsInAsyncPostBack Then

    End If

    In case the control implements ajax itself, I use this construct:

    Dim sm As ScriptManager = ScriptManager.GetCurrent(Me.Page)

    If sm.IsInAsyncPostBack Then
        
    If sm.AsyncPostBackSourceElementID.IndexOf("YourWebControlClassName") > -1 Then
             ...initialization code to run if the async postback was initiated by any child control on the web control.....

         End If
    End If  

    I find this to work well - speeding up my apps significantly, but might there be any reason not to do it, or is there perhaps a better way that I might have missed?  

     

  • Re: Dynamically loaded controls and ajax: how to prevent reloading the controls when not using page.IsPostback

    10-04-2007, 3:47 AM

    Good solution!

    Thanks for sharing it!

    Best Regards,

    Sincerely,
    Jin-Yu Yin
    Microsoft Online Community Support
Page 1 of 1 (2 items)
Microsoft Communities
Page view counter