Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I have my repeater's Itemcommand event not do a full page postback?

In my user control I have the following markup:

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

Whenever I click on the remove link button, it is performing a full page postback instead of just updating this control's panel. My master page has the following setup:

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True" />

Other parts of this application (which I inherited, and the old dev who wrote this is no longer around) seems to do partial page updates just fine. Am I doing something wrong?

like image 594
KallDrexx Avatar asked Jul 14 '13 17:07

KallDrexx


2 Answers

Try to register the linkbutton as async postback control, the appropriate place is the ItemCreated event which is triggered on every (async/full) postback:

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);
         }
     }
}
like image 102
Tim Schmelter Avatar answered Oct 14 '22 13:10

Tim Schmelter


Add this after ContentTemplate

    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="PageEditList" EventName="ItemCommand" />            
    </Triggers>
like image 27
Raghubar Avatar answered Oct 14 '22 12:10

Raghubar