UpdatePanelUpdateMode Enumeration
Represents the possible update modes for the content in an UpdatePanel control.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
| Member name | Description | |
|---|---|---|
| Always | The content of the UpdatePanel control is updated for all postbacks that originate from the page. This includes asynchronous postbacks. | |
| Conditional | The content of the UpdatePanel control is updated under the following conditions: |
The UpdatePanelUpdateMode enumeration defines the possible update modes for the content of an UpdatePanel control. The UpdateMode property must be set to one of the values of the UpdatePanelUpdateMode enumeration. The UpdatePanel control requires that the EnablePartialRendering property of the ScriptManager control be true for partial-page rendering to occur.
The default value of the UpdateMode property is Always.
If the UpdatePanel control is inside another UpdatePanel control and the parent panel is updated, the nested panel will also be updated regardless of the UpdateMode property value.
The following example declares two UpdatePanel controls. The first panel sets the UpdateMode property of an UpdatePanel control to Conditional. The second panel has UpdateMode set to Always by default. A button outside both panels is registered as an asynchronous postback control by using the RegisterAsyncPostBackControl method of the ScriptManager control. In the button's click event handler, the Update method of the first panel is called if more than five seconds have elapsed since its last update. In this scenario, the panel's content is updated only if the last panel update was more than five seconds ago. The second panel's content is always updated.
<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected DateTime LastUpdate { get { return (DateTime)(ViewState["LastUpdate"] ?? DateTime.Now); } set { ViewState["LastUpdate"] = value; } } protected void Button1_Click(object sender, EventArgs e) { if (LastUpdate.AddSeconds(5.0) < DateTime.Now) { UpdatePanel1.Update(); LastUpdate = DateTime.Now; } } protected void Page_Load(object sender, EventArgs e) { ScriptManager1.RegisterAsyncPostBackControl(Button1); if (!IsPostBack) { LastUpdate = DateTime.Now; } } </script> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title>UpdatePanelUpdateMode Example</title> </head> <body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:Panel ID="Panel1" GroupingText="UpdatePanel1" runat="server"> <asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <p> The content in this UpdatePanel only refreshes if five or more seconds have passed since the last refresh and the button in UpdatePanel2 was clicked. The time is checked server-side and the UpdatePanel.Update() method is called. Last updated: <strong> <%= LastUpdate.ToString() %> </strong> </p> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> <asp:Panel ID="Panel2" GroupingText="UpdatePanel2" runat="server"> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <p> This UpdatePanel always refreshes if the button is clicked. Last updated: <strong> <%= DateTime.Now.ToString() %> </strong> </p> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> <asp:Button ID="Button1" Text="Button1" runat="server" OnClick="Button1_Click" /> </div> </form> </body> </html>
Available since 3.5