Examples

The following example shows how to put controls inside an UpdatePanel control to reduce screen flicker when you post to the server. In this example, a Calendar and a DropDownList control are inside an UpdatePanel control. By default, the UpdateMode property is Always and the ChildrenAsTriggers property is true. Therefore, child controls of the panel cause an asynchronous postback.

In the following example, an UpdatePanel control is used in a master/detail scenario that shows orders and order details from the Northwind database. One UpdatePanel control contains the GridView control that displays a list of orders. A second UpdatePanel control contains a DetailsView control that displays the details of one order. When you select an order from the first table, details for that order are displayed in the second table. The second table is updated asynchronously based on the selection in the first table. The sorting and paging operations in the orders summary table also cause partial updates.

In the following example, an UpdatePanel control is used in the item template of a GridView control. UpdatePanel controls in each data row are generated automatically. Each row's UpdatePanel control contains a Label control to display the quantity of the item in that row and a Button control to decrease and increase the quantity.

Remarks

Introduction

UpdatePanel controls are a central part of AJAX functionality in ASP.NET. They are used with the ScriptManager control to enable partial-page rendering. Partial-page rendering reduces the need for synchronous postbacks and complete page updates when only part of the page has to be updated. Partial-page rendering improves the user experience because it reduces the screen flicker that occurs during a full-page postback and improves Web page interactivity.

Refreshing UpdatePanel Content

When partial-page rendering is enabled, a control can perform a postback that updates the whole page or an asynchronous postback that updates the content of one or more UpdatePanel controls. Whether a control causes an asynchronous postback and updates an UpdatePanel control depends on the following:

If the UpdateMode property of the UpdatePanel control is set to Always, the UpdatePanel control's content is updated on every postback that originates from the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls and postbacks from controls that are not inside UpdatePanel controls.

When a postback is caused by a control that is defined as a trigger by using the Triggers property of the UpdatePanel control. In this scenario, the control explicitly triggers an update of the panel content. The control can be either inside or outside the UpdatePanel control that the trigger is associated with.

When the ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers.

When the UpdatePanel control performs an asynchronous post, it adds a custom HTTP header. Some proxies remove this custom HTTP header. If this occurs, the server handles the request as a regular postback, which causes a client error. To resolve this issue, insert a custom form field when you perform asynchronous posts. Then check the header or the custom form field in server code.

UpdatePanel Usage

You can use multiple UpdatePanel controls to update multiple page regions independently. When the page that contains one or more UpdatePanel controls is first rendered, all the content of all UpdatePanel controls are rendered and sent to the browser. On subsequent asynchronous postbacks, the content of each UpdatePanel control might not be updated depending on the panel settings and on client or server logic for individual panels.

You can add an UpdatePanel control programmatically, but you cannot add triggers programmatically. To create trigger-like behavior, you can register a control on the page as an asynchronous postback control. You do this by calling the RegisterAsyncPostBackControl method of the ScriptManager control. You can then create an event handler that runs in response to the asynchronous postback, and in the handler, call the Update method of the UpdatePanel control.

Applying Styles

The UpdatePanel control accepts expando attributes. This lets you set a CSS class for the HTML elements that the controls render. For example, you might create the markup shown in the following example:

<asp:UpdatePanel runat="server" class="myStyle">
</asp:UpdatePanel>

The markup in the previous example renders HTML similar to the following when the page runs:

Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. You should not override this version of the FindControl method.