2.8. Working with Updates

Part of the complexity of partial page updates comes in establishing and maintaining relationships between elements on the page as the page evolves and as parts of the page are updated independently from one another. Of course, in real applications, you will have event handlers attached to DHTML Document Object Model (DOM) elements within an UpdatePanel that affect other parts of the page. When an asynchronous postback occurs, the event hookup will be lost and must be reestablished.

As updates occur, how do you effectively pull items out of the update and use these values elsewhere on the page? Listing 2-27 provides an example of how to accomplish this task.

Example 2-27. Using data from the updates that occur
<%@ Page Language="C#" %> <script runat="server"> protected override void OnLoad(EventArgs e) { string text = DateTime.Now.ToLongTimeString(); theTime.Text = text; theTime2.Text = text; } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Managing Updates</title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <script type="text/javascript"> var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_pageLoaded(pageLoaded); function pageLoaded(sender, pageLoadedEventArgs) { var panelsCreated = pageLoadedEventArgs.get_panelsCreated(); for(var i = 0; i < panelsCreated.length; i++) { if(panelsCreated[i].id === "panel1") { hookupPanelOne(); ...

Get Professional ASP.NET 3.5 AJAX now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.