gpt4 book ai didi

asp.net - 确定哪个 UpdatePanel 导致部分(异步)回发?

转载 作者:行者123 更新时间:2023-12-03 23:27:09 24 4
gpt4 key购买 nike

在一个页面中包含两个 UpdatePanels , 我怎么知道是哪个UpdatePanel导致局部PostBack ?

我的意思是在 Page_Load事件处理程序。

这是我的代码:

 <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"
onprerender="UpdatePanel1_PreRender">
<ContentTemplate>
<A:u1 ID="u1" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"
onprerender="UpdatePanel2_PreRender">
<ContentTemplate>
<A:u2 ID="u2" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>

我试过这段代码,但它几乎不起作用!
protected void Page_Load(object sender, EventArgs e)
{
if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)
{
if (UpdatePanel1.IsInPartialRendering)
{
// never enter to here
}
if (UpdatePanel2.IsInPartialRendering)
{
// neither here
}
}
}

任何帮助!

最佳答案

您可以使用 IsInPartialRendering UpdatePanel 的属性(property)用于确定特定面板是否导致部分回发的类:

protected void Page_Render(object sender, EventArgs e)
{
if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack) {
if (yourFirstUpdatePanel.IsInPartialRendering) {
// The first UpdatePanel caused the partial postback.
} else if (yourSecondUpdatePanel.IsInPartialRendering) {
// The second UpdatePanel caused the partial postback.
}
}
}

编辑:看来 IsInPartialRendering总是 false之前 Render阶段。由于您希望在 Load 期间获得该信息阶段,它不会按预期工作。见 this bug .

有一个解决方法 documented here这包括从 UpdatePanel 派生出你自己的类访问其 protected RequiresUpdate属性(property):
public class ExtendedUpdatePanel : UpdatePanel
{
public bool IsUpdating
{
get {
return RequiresUpdate;
}
}
}

更换后 asp:UpdatePanelExtendedUpdatePanel在您的页面标记中,上面的代码变为:
protected void Page_Load(object sender, EventArgs e)
{
if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack) {
if (yourFirstUpdatePanel.IsUpdating) {
// The first UpdatePanel caused the partial postback.
} else if (yourSecondUpdatePanel.IsUpdating) {
// The second UpdatePanel caused the partial postback.
}
}
}

关于asp.net - 确定哪个 UpdatePanel 导致部分(异步)回发?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4851694/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com