【问题标题】:ASP.NET triggering update panel refresh from code behindASP.NET 从后面的代码触发更新面板刷新
【发布时间】:2011-06-17 11:49:45
【问题描述】:

我的 ASP.NET 页面上有 2 个更新面板(updatepanel1 和 updatepanel2)。我想在后面的代码中触发 updatepanel2 从 updatepanel1 刷新/更新,所以在 updatepanel1_Load 事件中我将调用 updatepanel2.Update()。

但我需要一种方法来检查(在 updatepanel2_Load 中)异步回发是否是由 updatepanel1_Load 中的此调用引起的。有没有办法检查调用/回发触发器是否来自 updatepanel1?

感谢您的帮助

【问题讨论】:

    标签: .net asp.net ajax postback


    【解决方案1】:

    在单击其中一个更新面板时更新两个更新面板对您有好处吗?

    那么你应该使用触发器:

    <asp:UpdatePanel ID="updatePnl" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                  //your html
            </ContentTemplate>
    
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="updatePnl_SECOND" /> 
            </Triggers> 
    </asp:UpdatePanel>
    
    <asp:UpdatePanel ID="updatePnl_SECOND" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                  //your html
            </ContentTemplate>    
    </asp:UpdatePanel>
    

    在上述情况下,如果用户点击从 updatePnl_SECOND 回发的内容,updatePnl 也会更新。

    这对你有帮助吗?

    【讨论】:

    • 您需要UpdateMode="Conditional" 才能使用Triggers
    • 您好,感谢您的回复。不过,这并不是我真正想要的......因为在我的 updatepanel1_Load 事件中,我有一个代码块,我想在第二个更新面板开始更新之前执行 before。所以目前我在 updatepanel1_Load 中有一段代码,然后调用 updatepanel2.Update() .. 这只是我想要一种方法来测试调用是否来自 updatepanel2_Load 中的 updatepanel1。你知道这样的事情是否可行?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多