在我的用户控件中,我有以下标记:
<div id="pageEditsView" style="margin-left:540px">
<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="PageEditList"/>
</Triggers>
<ContentTemplate>
<asp:HiddenField runat="server" ID="CurrentPageId"/>
<asp:Label runat="server" ID="EditDisplayLabel" Visible="False">Edits tied to this page:</asp:Label>
<br/>
<ul>
<asp:Repeater runat="server" ID="PageEditList" OnItemCommand="PageEditList_ItemCommand">
<ItemTemplate>
<li>
<%# ((PageEdit)Container.DataItem).CachedName %>
(<asp:LinkButton ID="LinkButton1" runat="server" Text="remove" CommandName="remove" CommandArgument="<%# ((PageEdit)Container.DataItem).Id %>" />)
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</ContentTemplate>
</asp:UpdatePanel>
</div>
每当我点击删除链接按钮时,它都会执行整页回发,而不是仅仅更新此控件的面板。我的母版页有以下设置:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />
这个应用程序的其他部分(我继承了,并且写了这个的旧开发人员已经不在了)似乎可以进行部分页面更新。我做错了吗?
答案 0 :(得分:10)
尝试注册linkbutton as async postback control,适当的位置是每个(异步/完整)回发时触发的ItemCreated
事件:
protected void PageEditList_ItemCreated(Object Sender, RepeaterItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
ScriptManager scriptMan = ScriptManager.GetCurrent(this);
LinkButton btn = e.Item.FindControl("LinkButton1") as LinkButton;
if(btn != null)
{
btn.Click += LinkButton1_Click;
scriptMan.RegisterAsyncPostBackControl(btn);
}
}
}
答案 1 :(得分:1)
在ContentTemplate
之后添加此内容 <Triggers>
<asp:AsyncPostBackTrigger ControlID="PageEditList" EventName="ItemCommand" />
</Triggers>