由 UpdatePanel 内的 GridView 内的 LinkBut​​ton 触发的完整回发 [英] Full postback triggered by LinkButton inside GridView inside UpdatePanel

查看:39
本文介绍了由 UpdatePanel 内的 GridView 内的 LinkBut​​ton 触发的完整回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 UpdatePanel 中有一个 GridView.在模板字段中是我用来标记项目的按钮.从功能上讲,这工作正常,但按钮总是触发整页回发而不是部分回发.如何让按钮触发部分回发?

I have a GridView inside of a UpdatePanel. In a template field is a button I use for marking items. Functionally, this works fine, but the button always triggers a full page postback instead of a partial postback. How do I get the button to trigger a partial postback?

<asp:ScriptManager ID="ContentScriptManager" runat="server" />
<asp:UpdatePanel ID="ContentUpdatePanel" runat="server" ChildrenAsTriggers="true">
    <ContentTemplate>
        <asp:GridView ID="OrderGrid" runat="server" AllowPaging="false" AllowSorting="false"
            AutoGenerateColumns="false">
            <Columns>
                <asp:TemplateField HeaderText="">
                    <ItemTemplate>
                        <asp:LinkButton ID="MarkAsCompleteButton" runat="server" Text="MarkAsComplete"
                            CommandName="MarkAsComplete" CommandArgument='<%# Eval("Id") %>' />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Name" HeaderText="Name" />
                <asp:BoundField DataField="LoadDate" HeaderText="Load Date" />
                <asp:BoundField DataField="EmployeeCutOffDate" HeaderText="Cut Off Date" />
                <asp:BoundField DataField="IsComplete" HeaderText="Is Completed" />
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>

推荐答案

您需要将每个 LinkBut​​ton 注册为 AsyncPostBackTrigger.在您的 GridView 中绑定每一行后,您需要搜索 LinkBut​​ton 并通过代码隐藏进行注册,如下所示:

You need to register each and every LinkButton as an AsyncPostBackTrigger. After each row is bound in your GridView, you'll need to search for the LinkButton and register it through code-behind as follows:

protected void OrderGrid_RowDataBound(object sender, GridViewRowEventArgs e)  
{  
   LinkButton lb = e.Row.FindControl("MarkAsCompleteButton") as LinkButton;  
   ScriptManager.GetCurrent(this).RegisterAsyncPostBackControl(lb);  
}  

这还需要为 LinkBut​​ton 设置 ClientIDMode="AutoID",如此处所述(感谢 Răzvan Panda 指出这一点.

This also requires that ClientIDMode="AutoID" be set for the LinkButton, as mentioned here (thanks to Răzvan Panda for pointing this out).

这篇关于由 UpdatePanel 内的 GridView 内的 LinkBut​​ton 触发的完整回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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