1

以下是我的 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 文本值。但它会更新并显示更新面板内标签文本的更改值。我的理解是,当我们将更新模式属性设置为“有条件”时,更新面板内的内容不会更新(或在客户端渲染),当由于更新面板外部的控制而发生回发时,那么在我的情况下发生了什么。

4

2 回答 2

3

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

于 2013-04-10T12:27:59.977 回答
0

如果您只有一个更新面板,则毫无意义,请参阅此示例,它确实有意义。
尝试将第二个更新面板从 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();
    }
于 2012-05-20T10:27:51.447 回答