Professional Documents
Culture Documents
Partial
UpdatesPanel Control
Partial Page Updates
Page
Update
PanelUpdate
Control
The UpdatePanel is a container control without any UI of its own.
Defined in the System.Web.Extensions assembly, it belongs specifically to the
System.Web.UI namespace. The control class is declared as follows:
public class UpdatePanel : Control{ ...}
The control has a number of properties to control page updates and also exposes a
clientside object model.
When a control within the UpdatePanel triggers a postback, the UpdatePanel intervenes
to initiate the postback asynchronously and update just that portion of the page.
At the time the call to the server is made, the name of a JavaScript callback function
that will be called is provided, when the response has been received. That callback
function will receive the results and update various page controls accordingly.
Partial
UpdatesPanel Control
Partial Page Updates
Page
Update
PanelUpdate
Control
Partial Page Update is coordinated by the ScriptManager server control and the
client PageRequestManager class.
When partial-page updates are enabled, controls can asynchronously posted to
the server.
With an asynchronous postback, page updates are limited to regions of the page
that are enclosed in UpdatePanel controls and that are marked to be updated.
The server sends HTML markup for only the affected elements to the browser. In the
browser, the client PageRequestManager class performs Document Object Model
(DOM) manipulation to replace existing HTML with updated markup.
The UpdatePanel control sends an out-of-band request for fresh markup and then
updates the Document Object Model (DOM) tree when the response is ready.
Partial Page
UpdatesUpdateControl
Panel Control
Partial Page Updates
Update
Panel
- -Example
Example
The Example page has two labels and two buttons that can each cause a postback.
It simply updates the two labels with the current server time. Button1 and
its label are placed inside an UpdatePanel. Actually, they are put in the
ContentTemplate of the UpdatePanel.. The other label and button are left
outside the UpdatePanel
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server" language="C#" >
protected override void OnLoad(EventArgs e) {
base.OnLoad(e);
string theTime = DateTime.Now.ToLongTimeString();
for (int i = 0; i < 3; i++) {
theTime += "<br />" + theTime;
}
time1.Text = theTime;
time2.Text = theTime;
}
</script>
Partial
UpdatesPanel Control
Partial Page Updates
Page
Update
PanelUpdate
Control
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Basic Update Panel</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Label runat="server" ID="time1"></asp:Label><br /><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div style="border-style:solid;background-color:gray;">
<asp:Label runat="server" ID="time2"></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Inside Button" />
</div><br />
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button ID="Button2" runat="server" Text="Outside Button" />
</div>
</form>
</body>
</html>
Partial
UpdatesPanel Control
Partial Page Updates
Page
Update
PanelUpdate
Control
In the code-behind, both labels are
assigned the same time string in the
same way.
PageUpdatesHowPanel
UpdateControl
Panel Control
is refreshed?
Partial PagePartial
Updates
How Update
is refreshed?
rendering.
If the UpdateMode property is set to Always, the
UpdatePanel controls content is updated on every
postback that originates from anywhere on the page.
This includes asynchronous postbacks from controls that
PageUpdatesHowPanel
UpdateControl
Panel Control
is refreshed?
Partial PagePartial
Updates
How Update
is refreshed?
If the UpdateMode property is set to Conditional, the UpdatePanel controls content
is updated when one of the following is true:
When the UpdatePanel control is nested inside another UpdatePanel control and the
parent panel is updated.
When the ChildrenAsTriggers property is set to true and any 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 for the parent panel.
If the ChildrenAsTriggers property is set to false and the UpdateMode property is set
to Always, an exception is thrown. The ChildrenAsTriggers property is intended
Partial
Page UpdatesUpdate
Panel Control
Triggering
Updates
Partial Page
Updates
Update Panel
Control
Triggering
Updates
By default, any postback control inside an UpdatePanel control causes an
asynchronous postback and refreshes the panel's content.
A trigger is a binding that specifies which postback control and event cause
a panel to update. When the specified event of the trigger control is
raised (for example, a button's Click event), the update panel is
refreshed.
Partial
Page UpdatesUpdate
Panel Control
Triggering
Updates
Partial Page
Updates
Update Panel
Control
Triggering
Updates
PartialUpdates
Page UpdatesControl
Triggering Updates
Example
Partial Page
UpdateUpdate
PanelPanel
Control
Triggering
Updates
- Example
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Refreshing Update Panel through triggers</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1"
Text="Refresh Panel"
runat="server" />
<asp:ScriptManager ID="ScriptManager1"
runat="server" />
<asp:UpdatePanel ID="UpdatePanel1"
UpdateMode="Conditional"
runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" />
</Triggers>
<ContentTemplate>
<fieldset>
<legend>UpdatePanel content</legend>
<%=DateTime.Now.ToString() %>
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
PageUpdatesUpdate
Panel Control
with User
Controls
Partial PagePartial
Updates
Update Panel
Control
with User
Controls
PageUpdatesUpdate
Panel Control
with User
Controls
Partial PagePartial
Updates
Update Panel
Control
with User
Controls
Create a UserControl named
WebUserControl.ascx which performs
temperature conversion from Celsuis to
Fahrenheit.
protected void
ConvertButton_Click(obj
ect sender, EventArgs e)
{
double a = 1.8 *
temperature conversion
double.Parse(CelText.Tex
t) + 32;
FahText.Text =
a.ToString();
}
Partial Page
UpdatesThe Partial
Page
Update
Life Cycle
Partial Page Updates
The
Partial Page
Update
Life
Cycle
The page execution Lifecycle is not altered by the partial rendering feature.
The ScriptManager participates in the lifecycle to facilitate the partial page
updates. It coordinates gathering the renderings from the
UpdatePanels that need to be refreshed during an asynchronous post
and carrying the hidden fields necessary to make the following post
function correctly.
Controls that modify the ViewState, even if they are not in the
UpdatePanel being affected, do not have to take any special action to
ensure the change is available in subsequent requests.
Event validation, cross page posting, and ASP.NETs ability to maintain the
scroll position all continue to work when using the UpdatePanel.
Partial
Page UpdatesThe Panel
UpdateCautions
Panel Caution
Complexities
Partial Page
Updates
The Update
andand
Complexities
Complex controls that make heavy use of dynamically registered script
wont work correctly until they are updated to switch from using the
ClientScriptManager of ASP.NET 2.0 to using the ScriptManager
Web Parts
Partial
Page UpdatesThe Panel
UpdateCautions
Panel Caution
Complexities
Partial Page
Updates
The Update
andand
Complexities
The GridView and DetailsView controls already have a feature for using client
callbacks to paging and sorting. It is not enabled by default, but if the feature
is enabled, these controls cannot be used inside an UpdatePanel.
The FileUpload control also cant submit files as part of an asynchronous postback
The asp:substitution control
The way the ScriptManager extracts the contents needed for the partial page
updates in the 1.0 release, calling Response.Write during the execution of an
asynchronous postback will result in an error
Login, PasswordRecovery, ChangePassword, and CreateUserWizard controls
whose contents have not been converted to editable templates.