Learning Resources
Improving Performance with the AJAX Update Panel
The UpdatePanel control remove the requirement to refresh the whole page with each postback, which improves the user experience.
To implement the procedures in your own development environment you need:
-
Visual Studio or Visual Web Developer Express.
-
An AJAX-enabled ASP.NET Web site.
To use an UpdatePanel control
-
Create a new page and switch to Design view.
-
In the AJAX Extensions tab of the toolbox, double-click the ScriptManager control to add it to the page.
-
Double-click the UpdatePanel control to add it to the page.
-
Click inside the UpdatePanel control and then in the Standard tab of the toolbox, double-click the Label and Button controls to add them to the UpdatePanel control.
Note Make sure that you add the Label and Button controls inside the UpdatePanel control.
-
Double-click the Button control to add a handler for the button's Click event.
-
Add the following code to the Click handler, which sets the value of the label in the panel to the current time.
protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "Refreshed at " + DateTime.Now.ToString(); }
-
Save your changes and press CTRL+F5 to view the page in a browser.
-
Click the button.
Notice that the text in the panel changes to display the last time the panel's content was refreshed. This text is set in the button's Click event handler.
The example is styled to better show the region of the page that the UpdatePanel represents.
<%@ Page Language="C#" %> "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> "https://www.w3.org/1999/xhtml" > "server">
Untitled Page
The panel content changes every time that you click the button, but the whole page is not refreshed. By default, the ChildrenAsTriggers property of an UpdatePanel control is true. When this property is set to true, controls inside the panel participate in partial-page updates when any control in the panel causes a postback.