使用 GridView asp:ButtonField 为更新面板设置异步触发器

问题描述 投票:0回答:3

AsyncPostBackTrigger
控件中为
UpdatePanel
asp:ButtonField
设置
GridView
的正确语法是什么?

我需要为我的

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>

更新

我需要将

UpdateMode
ChildrenAsTriggers
属性设置为 true,因为我在
UpdatePanel
中包含其他按钮,这些按钮不会刷新
UpdatePanel
控件

asp.net gridview updatepanel
3个回答
0
投票

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


0
投票

Lance Harper 提到的所有内容都是正确的,但您还需要删除以下属性:

UpdateMode="Conditional"

设置该属性将阻止客户端事件的自动连接。本质上,您是在告诉 ASP.Net 您将自己执行此操作。


0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.