UpdatePanelUpdateMode 列挙型

定義

UpdatePanel コントロールの内容の有効な更新モードを表します。

public enum class UpdatePanelUpdateMode
public enum UpdatePanelUpdateMode
type UpdatePanelUpdateMode = 
Public Enum UpdatePanelUpdateMode
継承
UpdatePanelUpdateMode

フィールド

Always 0

UpdatePanel コントロールの内容は、ページから発生したすべてのポストバックで更新されます。 これには、非同期ポストバックも含まれます。

Conditional 1

コントロールの内容 UpdatePanel を更新する条件を指定します。詳細については、「解説」セクションを参照してください。

次の例では、2 つの UpdatePanel コントロールを宣言します。 最初のパネルは、 プロパティを UpdatePanel.UpdateModeConditional設定します。 2 番目のパネルは既定 UpdatePanel.UpdateMode で に Always 設定されています。 両方のパネルの外側にあるボタンは、 メソッドを使用 ScriptManager.RegisterAsyncPostBackControl して非同期ポストバック コントロールとして登録されます。 ボタンのクリック イベント ハンドラーでは、 UpdatePanel.Update 前回の更新から 5 秒以上経過した場合、最初のパネルの メソッドが呼び出されます。 このシナリオでは、最後のパネル更新が 5 秒以上前の場合にのみ、パネルのコンテンツが更新されます。 2 番目のパネルの内容は常に更新されます。


<%@ 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 ViewState("LastUpdate") IsNot 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>

注釈

UpdatePanelUpdateMode列挙体は プロパティによってUpdatePanel.UpdateMode使用され、コントロールのコンテンツに対して可能な更新モードをUpdatePanel定義します。 コントロールでは UpdatePanel 、部分ページ レンダリングを ScriptManager.EnablePartialRendering 実行するために プロパティ true が必要です。

プロパティの UpdatePanel.UpdateMode 既定値は です Always

コントロールが別UpdatePanelUpdatePanelコントロール内にあり、親パネルが更新された場合、入れ子になったパネルもプロパティ値にUpdateMode関係なく更新されます。

値は Conditional 、次の条件でコントロールの UpdatePanel 内容を更新します。

  • メソッドは UpdatePanel.Update 明示的に呼び出されます。

  • コントロールは、 プロパティを使用 UpdatePanel.Triggers してトリガーとして定義され、ポストバックが発生します。 このシナリオでは、コントロールはパネル コンテンツを更新するための明示的なトリガーです。 トリガー コントロールは、トリガーを定義するコントロールの UpdatePanel 内部または外部にすることができます。

  • UpdatePanel.ChildrenAsTriggersプロパティが にtrue設定され、コントロールの子コントロールによってUpdatePanelポストバックが発生します。 このシナリオでは、コントロールの UpdatePanel 子コントロールは、パネルを更新するための暗黙的なトリガーです。 入れ子になった UpdatePanel コントロールの子コントロールでは、トリガーとして明示的に定義されていない限り、外部 UpdatePanel コントロールは更新されません。

適用対象

こちらもご覧ください