An ASP.NET Blog
I work for Microsoft and help people and businesses make better use of technolgy to realize their full potential. The opinions mentioned herein are solely mine and do not reflect those of my employer.

UpdatePanel Internals - Part II - My Session at Tech Mela Contd.,

Sunday, August 12, 2007 7:52 PM

This article is in continuation with my earlier article on Update Panel Internals - TechMela Session 2 - Deep Dive: ASP.NET AJAX so you may want to check it before reading this, in case you havent read it already.

So, we left at the place where we were examining what is the HTML output when using a simple ScriptManager tag in your page, Adding an UpdatePanel, adding multiple UpdatePanels, UpdatePanels with Trigger etc.,  We were particularly drilling into the HTML Markup that is generated when adding an UpdatePanel and subsequently multiple UpdatePanels, Triggers etc., to your page, the array they get appended to, in the markup.  There is one more pending Array which might interest you, on what goes into it.  It would contain the normal Postback controls when declared as a trigger for the UpdatePanel.

When you declare an UpdatePanel with a Trigger, you can define a trigger to be either Async Postback or a normal Postback.  A normal PostBack would result in the whole page refreshing along with the Update Panel area.  Theoretically this sounds stupid since you can as well  put a normal button anywhere in the page and call the refresh.  However, there are scenarios where you would want a Trigger arising out of UpdatePanel to refresh the page and these trigger control IDs go into the third Array as seen in the following markup snippet (currently it is a blank array in this example).  The final thing '90' is the timeout which specifies when it will timeout before it can complete the async postback and here it is 90 seconds. 

Sys.WebForms.PageRequestManager.getInstance()._updateControls(['tUpdatePanel1','tUpdatePanel2','tUpdatePanel3'], ['Button4'], [], 90);

A word of note though is that, updateControls method is internal and it might change anytime with a next release / Service Pack so dont rely on this markup specifically.

What we originally intended was, to find out, how the UpdatePanel works :)  So lets proceed in that direction.

Like mentioned in the Part I, the Update Panel works in conjunction with the Script Manager defined in the page and calls the updateControls method which internally calls the _onFormSubmitCompleted method which is part of MicrosoftAjaxWebform.js file located in the Microsoft AJAX Library that is installed.

The sequence of Page Processing that happens for an AJAX Enabled Page is as follows:-

  • initializeRequest
  • beginRequest
  • pageLoading
  • pageLoaded
  • endRequest

All of the above are members of the PageRequestManager class which is the key class in Asynchronous postbacks.  You can imagine the PageRequestManager class as an equivalent to Page Class in a normal ASP.NET Web Page.  However, PageRequest Manager class doesnt replace the normal Page Class methods like Page_Init, Page_Load etc., The only difference in an asynchronous postback is that, the Page_Render method renders back only the modified HTML markup and it doesnt re-render the whole page as in the case of a normal ASP.NET Webform Pafe Life cycle.

So, if you want to handle an Async Postback execution and abort it, the class to take instance of is the PageRequestManager class.

We will explore more on PageRequestManager class and how to use its instance to work with the different methods in the next article.

Cheers !!!


Feedback

# re: UpdatePanel Internals - Part II - My Session at Tech Mela Contd.,

Hi Harish,

I was a bit disappointed that your "internals" session does not talk about HOW it renders ONLY the required HTML [HTML inside the UpdatePanel triggering the Async Postback].

I read [in the ONLY post I could find that talked about this] that there're TWO HtmlTextWriters as ASP.Net needs to Render ALL HTML in order for it to compute EventValidationhash.

http://blogs.interknowlogy.com/joelrumerman/archive/2006/04/23/1933.aspx

I used reflector to search and came up dry on Microsoft.Web.UI.DummyHtmlTextWriter...

Help?

Regards, Vyas 9/26/2007 1:11 AM | Vyas Bharghava

# re: UpdatePanel Internals - Part II - My Session at Tech Mela Contd.,

I had a query regarding multiple update panels.
I have a user control which contains one update panel.This user control contains a hidden textbox .
I am updating the updatepanels on basis of a timer control in javascripts which raises a postback.

I have placed two instances of this user control in another page say for eg. CIndexPage.aspx.
Now the Script manager is also placed in the same page ie CIndexPage.aspx.

Will the two updatepanels wrk independently.
I have tried but the hidden values are not getting updated for the same updatepanel and getting interchanged.

Please if someone cld help me with this.

Regards,
Shweta
10/31/2007 10:36 PM | Shweta

Post a comment





 

Please add 5 and 5 and type the answer here: