【问题标题】:Update mode property of UpdatePanelUpdatePanel 的更新模式属性
【发布时间】:2012-05-20 08:38:49
【问题描述】:

以下是我的 ASPX 代码。

<form id="form1" runat="server">
  <div>
   <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
   <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
   <asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel1" runat="server">
   <ContentTemplate>
     <asp:Label ID="lblid" runat="server" Text="Label"></asp:Label>
   </ContentTemplate>
   </asp:UpdatePanel>
   <asp:Button ID="btnid" runat="server" Text="Button"/>
  </div>
</form>

我有一个更新面板控件,并且在更新面板控件中包含了单个标签控件。我在更新面板控件之外有 Button 和 Lable,在 page_load 期间我更新了两个 lable 控件的文本值,如下所示。

protected void Page_Load(object sender, EventArgs e)
{
  lblid.Text = DateTime.Now.ToString();
  Label1.Text = DateTime.Now.ToString();
}

我已将更新模式属性设置为“有条件”,这样当用户单击更新面板外的按钮控件时,它不应更改 ipdate 面板内的 lable 文本值。但它会更新并显示更新面板内标签文本的更改值。我的理解是,当我们将更新模式属性设置为“有条件”时,更新面板内的内容不会更新(或在客户端渲染)当由于更新面板外部的控制而发生回发时,那么在我的情况下发生了什么。

【问题讨论】:

    标签: asp.net ajax updatepanel


    【解决方案1】:

    单击 UpdatePanel 外部的按钮会导致整个页面回发。在整个页面被回发的情况下,UpdatePanel 不能阻止它里面的内容被刷新。

    【讨论】:

      【解决方案2】:

      如果你只有一个更新面板,那就没有意义了 看看这个确实有意义的例子。
      尝试将第二个更新面板从 Conditional 更改为 Always
      ASPX:

      <asp:ScriptManager ID="ScriptManager1" runat="server">
          </asp:ScriptManager>
      <div>
      
          <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
          <asp:UpdatePanel  ID="UpdatePanel1" runat="server">
              <ContentTemplate>
                  <asp:Label ID="lblid" runat="server" Text="Label"></asp:Label>
                  <asp:Button ID="btnid" runat="server" Text="Button" />
              </ContentTemplate>
          </asp:UpdatePanel>
      
          <asp:UpdatePanel UpdateMode="Conditional"  ID="UpdatePanel2" runat="server">
              <ContentTemplate>
                  <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>             
              </ContentTemplate>
          </asp:UpdatePanel>
      
      </div>
      

      CS:

      protected void Page_Load(object sender, EventArgs e)
          {
              lblid.Text = DateTime.Now.ToString();
              Label1.Text = DateTime.Now.ToString();
              Label2.Text = DateTime.Now.ToString();
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-01-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-04-28
        • 1970-01-01
        相关资源
        最近更新 更多