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.
-
If the UpdateMode property is set to Conditional, the UpdatePanel control's content is updated in the following circumstances:
-
When you call the Update() method of the UpdatePanel control explicitly.
-
When the UpdatePanel control is nested inside another UpdatePanel control, and the parent panel is updated.
-
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.
-
The combination of setting the ChildrenAsTriggers property to false and the UpdateMode property to Always is not allowed and will throw an exception.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ConditionalUpdatePanelExample.aspx.cs" Inherits="ConditionalUpdatePanelExample" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="scriptManager1" runat="server" />
<div>
<asp:Panel ID="conditionalPanel" runat="server">
<asp:UpdatePanel ID="conditionalUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<p>
Conditional:
<strong><%= DateTime.Now.ToBinary() %></strong>
</p>
<asp:UpdatePanel ID="nestedUpdatePanel" runat="server" UpdateMode="Conditional"
ChildrenAsTriggers="true">
<ContentTemplate>
<p>
Nested Conditional:
<string><%= DateTime.Now.ToBinary() %></string>
<asp:Button ID="uxNestedConditionalButton" runat="server" Text="Nested Conditional" />
</p>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</div>
<div>
<asp:Button ID="uxButton" runat="server" Text="Do some server side stuff"
OnClick="Button_Click" />
</div>
</form>
<a href="Default.aspx">Previous one</a>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class ConditionalUpdatePanelExample : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.scriptManager1.RegisterAsyncPostBackControl(this.uxButton);
}
protected void Button_Click(object sender, EventArgs e) {
this.conditionalUpdatePanel.Update();
}
}