问题描述
我有一个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:LinkButton的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>
您需要在每一个注册的LinkButton作为AsyncPostBackTrigger。每排在你的GridView绑定后,你需要搜索的LinkButton,并通过code寄存器,如下所示:
保护无效OrderGrid_RowDataBound(对象发件人,GridViewRowEventArgs E)
{
LinkButton的磅= e.Row.FindControl(MarkAsCompleteButton)作为LinkButton的;
ScriptManager.GetCurrent(本).RegisterAsyncPostBackControl(磅);
}
的ClientIDMode =自动识别为LinkButton的(见下面的评论)
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通过LinkButton的触发完全回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!