About Me

Professional Practical HumanBeing

Saturday, November 13, 2010

UpdatePanel

The UpdatePanel control, is responsible for partial page rendering of a web page. Meaning only part of a page is posted back to the server instead of the entire page. This helps to build rich User Interfaces, provides improved performance and quicker response time.

Properties of the UpdatePanel
The content of the UpdatePanel described in the code listing is declared within the ContentTemplate tag. The content of the ContentTemplate tag is posted back to the server asynchronously. Create the ContentTemplate's content declaratively or programmatically.

By default the UpdateMode property of UpdatePanel is set to ‘Always’ meaning the contents of the UpdatePanel will be rendered whenever the page is posted back to server. Conversely setting the UpdateMode property to ‘Conditional’ means the content of the UpdatePanel will be rendered in the following circumstances:

  • When the Update method is explicitly called from the UpdatePanel control
  • When a control defined as a trigger within the Triggers tag in the UpdatePanel and is responsible for postback. The control triggers an update of the contents within the panel explicitly and the control can be present either inside or outside of the UpdatePanel control.
  • When a child control of an UpdatePanel control is responsible for postback and the ChildrenAsTriggers property is set to true
  • When the UpdatePanel control is nested inside another UpdatePanel control and the parent UpdatePanel control is updated

The following code shows the Update method of the UpdatePanel being called provided the condition within the if block is satisfied.

Code Listing

protected void Button1_Click(object sender, EventArgs e)
{
if (condition.....)
{
UpdatePanel1.Update();
}
}

Nested Updat

ePanel Controls
The UpdatePanel controls can be nested. If the parent UpdatePanel is refreshed, all the nested UpdatePanels are refreshed also.

The element
The above code sends not only the label’s code when asynchronous post back occurs, but also the button’s code and the entire section of the UpdatePanel back to the client. However only the part which needs updating can be sent back to the server - meaning only the label part. To do this,

Trigger elements need to be added into the UpdatePanel control as shown in the Code Listing below:



The Trigger can be generated by any control in the
form. It can be of two types:
AsynchronousPostBackTrigger and PostBackTrigger. In this example AsynchronousPostBackTrigger is used. The PostBackTrigger will cause a full page post back whereas the AsynchronousPostBackTrigger will cause only a Asynchronous PostBack.






Source :-

No comments:

Post a Comment