UpdatePanelUpdateMode UpdatePanelUpdateMode UpdatePanelUpdateMode UpdatePanelUpdateMode Enum

定义

表示 UpdatePanel 控件中内容可能的更新模式。Represents the possible update modes for the content in an UpdatePanel control.

public enum class UpdatePanelUpdateMode
public enum UpdatePanelUpdateMode
type UpdatePanelUpdateMode = 
Public Enum UpdatePanelUpdateMode
继承
UpdatePanelUpdateModeUpdatePanelUpdateModeUpdatePanelUpdateModeUpdatePanelUpdateMode

字段

Always Always Always Always 0

对于源于页面的所有回发,UpdatePanel 控件的内容都会进行更新。The content of the UpdatePanel control is updated for all postbacks that originate from the page. 其中也包括异步回发。This includes asynchronous postbacks.

Conditional Conditional Conditional Conditional 1

指定了更新 UpdatePanel 控件内容的若干条件;有关信息信息,请参阅“备注”部分。Specifies a number of conditions under which the content of the UpdatePanel control is updated; see the Remarks section for more information.

示例

下面的示例声明了UpdatePanel两个控件。The following example declares two UpdatePanel controls. 第一个面板将UpdatePanel.UpdateMode属性设置为。 ConditionalThe first panel sets the UpdatePanel.UpdateMode property to Conditional. 默认情况下, UpdatePanel.UpdateMode第二Always个面板设置为。The second panel has UpdatePanel.UpdateMode set to Always by default. 使用ScriptManager.RegisterAsyncPostBackControl方法将两个面板外的按钮注册为异步回发控件。A button outside both panels is registered as an asynchronous postback control by using the ScriptManager.RegisterAsyncPostBackControl method. 在按钮的 click 事件处理程序中, UpdatePanel.Update如果自上次更新后超过5秒, 则会调用第一个面板的方法。In the button's click event handler, the UpdatePanel.Update method of the first panel is called if more than five seconds have elapsed since its last update. 在这种情况下, 仅当上一次面板的更新超过5秒时, 面板的内容才会更新。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>

<%@ 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
        Get
            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
            UpdatePanel1.Update()
            LastUpdate = DateTime.Now
        End If
    End Sub

    Protected Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
        ScriptManager1.RegisterAsyncPostBackControl(Button1)
        If Not IsPostBack Then
            LastUpdate = DateTime.Now
        End If
    End Sub
</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"
                                   runat="server"
                                   UpdateMode="Conditional">
                    <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>

注解

枚举由UpdatePanel.UpdateMode属性使用, 并定义UpdatePanel控件内容的可能更新模式。 UpdatePanelUpdateModeThe UpdatePanelUpdateMode enumeration is used by the UpdatePanel.UpdateMode property and defines the possible update modes for the content of an UpdatePanel control. 控件要求ScriptManager.EnablePartialRendering 属性true用于进行部分页呈现。 UpdatePanelThe UpdatePanel control requires that the ScriptManager.EnablePartialRendering property be true for partial-page rendering to occur.

UpdatePanel.UpdateMode属性的默认值为AlwaysThe default value of the UpdatePanel.UpdateMode property is Always.

如果控件位于另一个UpdatePanel控件内并更新了父面板, 则无论UpdateMode属性值如何, 都将更新嵌套面板。 UpdatePanelIf 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.

值在以下条件下更新UpdatePanel控件的内容: ConditionalThe Conditional value updates the content of the UpdatePanel control under the following conditions:

  • UpdatePanel.Update方法是显式调用的。The UpdatePanel.Update method is called explicitly.

  • 使用UpdatePanel.Triggers属性将控件定义为触发器, 并导致回发。A control is defined as a trigger by using the UpdatePanel.Triggers property and causes a postback. 在这种情况下, 控件是用于更新面板内容的显式触发器。In this scenario, the control is an explicit trigger for updating the panel content. 触发器控件可以在定义该触发器的UpdatePanel控件内部或外部。The trigger control can be either inside or outside the UpdatePanel control that defines the trigger.

  • 属性设置为true , 并且UpdatePanel控件的子控件导致回发。 UpdatePanel.ChildrenAsTriggersThe UpdatePanel.ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. 在此方案中, UpdatePanel控件的子控件是用于更新面板的隐式触发器。In this scenario, child controls of the UpdatePanel control are implicit triggers for updating the panel. 嵌套UpdatePanel控件的子控件不会导致外部UpdatePanel控件被更新, 除非将其显式定义为触发器。Child controls of nested UpdatePanel controls do not cause the outer UpdatePanel control to be updated unless they are explicitly defined as triggers.

适用于

另请参阅