确定的UpdatePanel使得部分(异步)回发? [英] Determine which UpdatePanel causes the partial (asynchronous) PostBack?

查看:193
本文介绍了确定的UpdatePanel使得部分(异步)回发?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个页面包含两个的UpdatePanel ,我怎么能知道哪些的UpdatePanel 使得部分回发

In a page contains two UpdatePanels, How can I know which UpdatePanel causes the partial PostBack ?

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

I mean in the Page_Load event handler.

这是我的code:

 <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>

我想这code,但它没有工作alost!

I tried this code, but it isn't worked alost!

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 类的属性来确定特定面板造成局部回传:

You can use the IsInPartialRendering property of the UpdatePanel class to determine if a specific panel caused the partial postback:

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 总是的<$ C之前$ C>渲染阶段。既然你想要的加载阶段过程中的信息,预期这将无法正常工作。见<一href=\"http://connect.microsoft.com/VisualStudio/feedback/details/600282/updatepanel-isinpartialrendering-is-always-false\">this错误。

It appears that IsInPartialRendering is always false before the Render phase. Since you want that information during the Load phase, it won't work as expected. See this bug.

有在这里记录了解决办法 ,由从派生自己的类UpdatePanel的来访问它保护的 RequiresUpdate 属性:

There's a workaround documented here that consists in deriving your own class from UpdatePanel to access its protected RequiresUpdate property:

public class ExtendedUpdatePanel : UpdatePanel
{
    public bool IsUpdating
    {
        get {
            return RequiresUpdate;
        }
    }
}

更换后 ASP:的UpdatePanel ExtendedUpdatePanel 在你的网页标记时,code以上变为:

After replacing asp:UpdatePanel with ExtendedUpdatePanel in your page markup, the code above becomes:

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.
        }
    }
}

这篇关于确定的UpdatePanel使得部分(异步)回发?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆