O'Reilly logo

Professional ASP.NET 3.5 AJAX by Matt Gibbs, Dan Wahlin, Bill Evjen, Dave Reed

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required