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

问题描述

我有一个GridView一个UpdatePanel的内部。在模板字段是一个按​​钮,我使用的标志项目。在功能上,这工作正常,但按钮始终触发一整页回传,而不是局部回传。我如何获得按钮,触发部分回发?

 < ASP:的ScriptManager ID =ContentScriptManager=服务器/>
< ASP:的UpdatePanel ID =ContentUpdatePanel=服务器ChildrenAsTriggers =真>
    <&的ContentTemplate GT;
        < ASP:GridView控件ID =OrderGrid=服务器AllowPaging =假AllowSorting =假
            的AutoGenerateColumns =假>
            <柱体和GT;
                < ASP:的TemplateField的HeaderText =>
                    <&ItemTemplate中GT;
                        < ASP:LinkBut​​ton的ID =MarkAsCompleteButton=服务器文本=MarkAsComplete
                            的CommandName =MarkAsCompleteCommandArgument ='<%#的eval(ID)%GT;' />
                    < / ItemTemplate中>
                < / ASP:的TemplateField>
                < ASP:BoundField的数据字段=名称的HeaderText =名称/>
                < ASP:BoundField的数据字段=LoadDate的HeaderText =加载日期/>
                < ASP:BoundField的数据字段=EmployeeCutOffDate的HeaderText =截止日期/>
                < ASP:BoundField的数据字段=IsComplete的HeaderText =完成/>
            < /专栏>
        < / ASP:GridView的>
    < /&的ContentTemplate GT;
< / ASP:的UpdatePanel>


解决方案

您需要在每一个注册的LinkBut​​ton作为AsyncPostBackTrigger。每排在你的GridView绑定后,你需要搜索的LinkBut​​ton,并通过code寄存器,如下所示:

 保护无效OrderGrid_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
   LinkBut​​ton的磅= e.Row.FindControl(MarkAsCompleteButton)作为LinkBut​​ton的;
   ScriptManager.GetCurrent(本).RegisterAsyncPostBackControl(磅);
}

的ClientIDMode =自动识别为LinkBut​​ton的(见下面的评论)

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>
解决方案

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 as follows:

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

ClientIDMode="AutoID" for the LinkButton (see comment below)

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

10-23 03:07