UpdatePanelUpdateMode Enumeração

Definição

Representa os modos de atualização possíveis para o conteúdo em um controle 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
Herança
UpdatePanelUpdateMode

Campos

Always 0

O conteúdo do controle UpdatePanel é atualizado para todos os postbacks que se originam da página.The content of the UpdatePanel control is updated for all postbacks that originate from the page. Isso inclui os postbacks assíncronos.This includes asynchronous postbacks.

Conditional 1

Especifica um número de condições em que o conteúdo do controle UpdatePanel será atualizado. Confira a seção Comentários para obter mais informações.Specifies a number of conditions under which the content of the UpdatePanel control is updated; see the Remarks section for more information.

Exemplos

O exemplo a seguir declara dois UpdatePanel controles.The following example declares two UpdatePanel controls. O primeiro painel define a UpdatePanel.UpdateMode propriedade como Conditional .The first panel sets the UpdatePanel.UpdateMode property to Conditional. O segundo painel foi UpdatePanel.UpdateMode definido como Always por padrão.The second panel has UpdatePanel.UpdateMode set to Always by default. Um botão fora dos dois painéis é registrado como um controle de postback assíncrono usando o ScriptManager.RegisterAsyncPostBackControl método.A button outside both panels is registered as an asynchronous postback control by using the ScriptManager.RegisterAsyncPostBackControl method. No manipulador de eventos de clique do botão, o UpdatePanel.Update método do primeiro painel é chamado se mais de cinco segundos tiverem decorrido desde sua última atualização.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. Nesse cenário, o conteúdo do painel será atualizado somente se a última atualização do painel tiver mais de cinco segundos.In this scenario, the panel's content is updated only if the last panel update was more than five seconds ago. O conteúdo do segundo painel é sempre atualizado.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>

Comentários

A UpdatePanelUpdateMode enumeração é usada pela UpdatePanel.UpdateMode propriedade e define os modos de atualização possíveis para o conteúdo de um UpdatePanel controle.The UpdatePanelUpdateMode enumeration is used by the UpdatePanel.UpdateMode property and defines the possible update modes for the content of an UpdatePanel control. O UpdatePanel controle exige que a ScriptManager.EnablePartialRendering propriedade seja true para que a renderização parcial da página ocorra.The UpdatePanel control requires that the ScriptManager.EnablePartialRendering property be true for partial-page rendering to occur.

O valor padrão da UpdatePanel.UpdateMode propriedade é Always .The default value of the UpdatePanel.UpdateMode property is Always.

Se o UpdatePanel controle estiver dentro de outro UpdatePanel controle e o painel pai for atualizado, o painel aninhado também será atualizado, independentemente do UpdateMode valor da propriedade.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.

O Conditional valor atualiza o conteúdo do UpdatePanel controle sob as seguintes condições:The Conditional value updates the content of the UpdatePanel control under the following conditions:

  • O UpdatePanel.Update método é chamado explicitamente.The UpdatePanel.Update method is called explicitly.

  • Um controle é definido como um gatilho usando a UpdatePanel.Triggers propriedade e causa um postback.A control is defined as a trigger by using the UpdatePanel.Triggers property and causes a postback. Nesse cenário, o controle é um gatilho explícito para atualizar o conteúdo do painel.In this scenario, the control is an explicit trigger for updating the panel content. O controle de gatilho pode estar dentro ou fora do UpdatePanel controle que define o gatilho.The trigger control can be either inside or outside the UpdatePanel control that defines the trigger.

  • A UpdatePanel.ChildrenAsTriggers propriedade é definida como true e um controle filho do UpdatePanel controle causa um postback.The UpdatePanel.ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. Nesse cenário, controles filho do UpdatePanel controle são gatilhos implícitos para atualizar o painel.In this scenario, child controls of the UpdatePanel control are implicit triggers for updating the panel. Controles filho de controles aninhados UpdatePanel não fazem com que o UpdatePanel controle externo seja atualizado, a menos que sejam explicitamente definidos como gatilhos.Child controls of nested UpdatePanel controls do not cause the outer UpdatePanel control to be updated unless they are explicitly defined as triggers.

Aplica-se a

Confira também