UpdatePanelUpdateMode Enumeration


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Represents the possible update modes for the content in an UpdatePanel control.

Namespace:   System.Web.UI
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

Public Enumeration UpdatePanelUpdateMode

Member nameDescription

The content of the UpdatePanel control is updated for all postbacks that originate from the page. This includes asynchronous postbacks.


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="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Protected Property LastUpdate() As DateTime
            If Not ViewState("LastUpdate") Is Nothing Then
                Return ViewState("LastUpdate")
            Else : Return DateTime.Now()
            End If
        End Get
        Set(ByVal Value As DateTime)
            ViewState("LastUpdate") = Value
        End Set
    End Property

    Protected Sub Button1_Click(ByVal Sender As Object, ByVal E As EventArgs)
        If (LastUpdate.AddSeconds(5.0) < DateTime.Now) Then
            LastUpdate = DateTime.Now
        End If
    End Sub

    Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
        If Not IsPostBack Then
            LastUpdate = DateTime.Now
        End If
    End Sub

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>UpdatePanelUpdateMode Example</title>
    <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1"
                               runat="server" />
            <asp:Panel ID="Panel1"
                <asp:UpdatePanel ID="UpdatePanel1"
                            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() %>
            <asp:Panel ID="Panel2"
                <asp:UpdatePanel ID="UpdatePanel2"
                            This UpdatePanel always refreshes if the button is clicked.
                            Last updated: <strong>
                                <%= DateTime.Now.ToString() %>
            <asp:Button ID="Button1" Text="Button1" runat="server" OnClick="Button1_Click" />

.NET Framework
Available since 3.5
Return to top