我有一个默认的VS 2013 ASP.NET Webform项目,其中一个主页面包含ScriptManager,另一个内容页包含UpdatePanel。这是我在内容页面的ContentPlaceHolder中的内容:
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
<ContentTemplate>
Updated at: <%=DateTime.Now.ToString() %>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Button Text="Click" runat="server" />
</asp:Content>
每次我单击"click"按钮时,UpdatePanel内的时间都会被刷新,即使我将UpdateMode设置为"Conditional"也是如此。
我的理解是,显示时间的ASP.NET代码应该只在我第一次获取页面时执行,然后由为面板定义的任何触发器执行(因为面板的更新模式是有条件的)。
我错了吗?如果是,为什么?
按钮应该放在另一个更新面板内。
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
Updated at: <%=DateTime.Now.ToString() %>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Button1" Text="Click" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
希望有帮助,
要了解更多关于更新面板的信息,请访问链接
http://ajax.net-tutorials.com/controls/updatepanel-control/