UpdatePanel 不执行部分页面更新,并且 IsInAsyncPostBack 始终为 false
我正在尝试使用 UpdatePanel,但无法使部分页面更新生效。
当我查看 ScriptManager 的 IsInAsyncPostBack 属性时,它始终为 false。
这是重现该问题的页面。它有一个 ScriptManager、一个 UpdatePanel、更新面板中的 LinkButton 以及通过 Triggers 集合连接到 UpdatePanel 的 Button。
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
if (IsPostBack)
Label1.Text += " - Postback!";
if (ScriptManager1.IsInAsyncPostBack)
Label1.Text += " - Async!";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>Panel 1:<asp:Label runat=server ID=Label1 /><br />
<asp:LinkButton runat=server ID="LinkButton1" Text="Update!"></asp:LinkButton></ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /></Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" Text="Refresh Panel 1" runat="server" UseSubmitBehavior=false />
</form>
</body>
</html>
如果我运行此代码并单击任一按钮,我会看到“Panel 1:2/8/2010 3:38:41 PM - Postback!”
我预计单击任一按钮都会导致 UpdatePanel1 的部分页面更新,IsInAsyncPostBack 将为 true,并且“-异步!”将被附加到 Label1。
知道为什么 IsInAsyncPostBack 总是 false 吗?
I'm attempting to use an UpdatePanel, but can't get partial-page updates to work.
When I look at the ScriptManager's IsInAsyncPostBack property, it's always false.
Here's a page that reproduces the issue. It has a ScriptManager, an UpdatePanel, a LinkButton within the update panel, and a Button wired up to the UpdatePanel via the Triggers collection.
<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
if (IsPostBack)
Label1.Text += " - Postback!";
if (ScriptManager1.IsInAsyncPostBack)
Label1.Text += " - Async!";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>Panel 1:<asp:Label runat=server ID=Label1 /><br />
<asp:LinkButton runat=server ID="LinkButton1" Text="Update!"></asp:LinkButton></ContentTemplate>
<Triggers><asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /></Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" Text="Refresh Panel 1" runat="server" UseSubmitBehavior=false />
</form>
</body>
</html>
If I run this code and click on either of the buttons, I see "Panel 1:2/8/2010 3:38:41 PM - Postback!"
I expected that clicking either button would cause a partial-page update for UpdatePanel1, that IsInAsyncPostBack would be true, and that " - Async!" would be appended to Label1.
Any idea why IsInAsyncPostBack is always false?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
web.config 文件具有 。当设置为 Legacy 模式时,部分页面更新不起作用。 (事实上,他们会默默地失败 - BOO!嘶嘶声!)
将模式更改为过渡模式解决了这个问题。
http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx
The web.config file had <xhtmlConformance mode="Legacy"/>. When the Legacy mode is set, partial-page updates don't work. (In fact, they fail silently - BOO! HISS!)
Changing the mode to Transitional resolved this issue.
http://weblogs.asp.net/scottgu/archive/2006/12/10/gotcha-don-t-use-xhtmlconformance-mode-legacy-with-asp-net-ajax.aspx