Wednesday, July 1, 2009

Using the ASP.NET UpdatePanel Control with Data-Bound Controls

You can create a richer user experience in your AJAX-enabled ASP.NET applications by using partial-page rendering. Partial-page rendering removes the need for the whole page to refresh as the result of a postback. Instead, you can specify only the region of the page to be refreshed. As a result, users no longer see the whole page reload with every postback.

This topic assumes that you are familiar with the UpdatePanel control. If not, review the following topics:

You can enable partial-page rendering by using the UpdatePanel and ScriptManager Web server controls. The UpdatePanel control identifies a region of a page that can be updated. The ScriptManager control keeps track of the UpdatePanel controls that are on a page and the controls that trigger the UpdatePanel controls to refresh. Controls inside an UpdatePanel control that cause a postback are automatically identified as triggers for the update panel. You can also specify controls that are controls outside an UpdatePanel control. External triggers can be child controls of another UpdatePanel control. For more information, see Partial-Page Rendering Overview and UpdatePanel Control Overview.

This topic contains the following:

There is no limit to the number of UpdatePanel controls that you can put on a page. As a result, you can specify regions of a page that are refreshed independently of the whole page and independently of each other.

By default, the UpdateMode property of an UpdatePanel control is set to Always. This means that whenever a partial-page refresh is triggered, the UpdatePanel control refreshes the page, even if the trigger was not for that UpdatePanel control. To make sure that the UpdatePanel control is refreshed only when it has been triggered, you can set the UpdateMode property of the UpdatePanel control to Conditional.

The following example includes two UpdatePanel controls. One control includes Web controls that accept user input, and the other control displays what the user enters. Each UpdatePanel control has its UpdateMode property set to Conditional. As a result, if a user clicks the Cancel button to clear the fields of the input form, only the input form of the UpdatePanel control is refreshed. If a user clicks the Insert button to submit the form, both UpdatePanel controls are refreshed.


See full detail: http://msdn.microsoft.com/en-us/library/bb386452.aspx

No comments: