6

在我的用户控件中,我有以下标记:

<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" />

这个应用程序的其他部分(我继承的,写这个的老开发者不再存在)似乎可以很好地进行部分页面更新。难道我做错了什么?

4

2 回答 2

12

尝试将链接按钮注册为异步回发控件,适当的位置是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);
         }
     }
}
于 2013-07-14T17:27:28.317 回答
1

在 ContentTemplate 之后添加

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="PageEditList" EventName="ItemCommand" />            
    </Triggers>
于 2013-07-14T17:26:42.883 回答