【问题标题】:Set an async trigger for an Update Panel with a GridView asp:ButtonField使用 GridView asp:ButtonField 为更新面板设置异步触发器
【发布时间】:2009-06-03 20:49:21
【问题描述】:

使用来自GridView 控件的asp:ButtonFieldUpdatePanel 设置AsyncPostBackTrigger 的正确语法是什么?

我需要为GridView 中的每个 asp:ButtonField 设置一个“AsyncPostBackTrigger”

这是我的源代码

<asp:UpdatePanel ID="MyUpdatePanel" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional">
    <Triggers>
    </Triggers>
    <ContentTemplate>
        <asp:GridView ID="MyGridView" runat="server" AutoGenerateColumns="false">       
            <Columns>        
                <asp:ButtonField ButtonType="Link" CommandName="Button1" SelectText="Click Me!" />        
                <asp:ButtonField ButtonType="Link" CommandName="Button2" SelectText="No Click Me!" />    
            </Columns>
        </asp:GridView>
    </ContentTemplate> 
</asp:UpdatePanel>

更新

我需要将UpdateModeChildrenAsTriggers 属性设置为true,因为UpdatePanel 中包含其他不刷新UpdatePanel 控件的按钮

【问题讨论】:

    标签: asp.net gridview updatepanel


    【解决方案1】:

    将 ChildrenAsTriggers 属性设置为 true 将导致任何会导致更新面板中的回发的控件使其刷新。如果您希望使用更新面板之外的控件来触发该更新面板的刷新,则只需要使用 triggers 元素。在这种情况下,您甚至不需要 triggers 元素。

    【讨论】:

    • 查看给 Josh 的评论
    【解决方案2】:

    Lance Harper 提到的一切都是真的,但您还需要删除以下属性:

    UpdateMode="Conditional"
    

    拥有该属性将阻止客户端事件的自动连接。本质上,您是在告诉 ASP.Net,您将自己做这件事。

    【讨论】:

    • 我希望将条件属性设置为 true,因为面板中有不会导致 UpdatePanel 刷新的按钮。
    【解决方案3】:

    是否可以使用模板字段代替命令字段,并在单击命令按钮时强制更新(UpdatePanel.Update())面板?

    【讨论】:

    • 我的代码示例有误。它应该是一个 asp:ButtonField 列,而不是 asp:CommandField 列。我更新了我的代码示例
    • 我认为我的建议仍然有效。使用模板字段,按下按钮时执行命令,然后更新面板。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-20
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多