How can I use the Itemcommand relay event but not make a full page back?

In my 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 the delete link button, it performs a full page postback instead of updating this control panel. My main page has the following settings:

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

Other parts of this application (which I inherited, and the old developer who wrote this, no longer exist) seem to make partial page updates just fine. Am I doing something wrong?

+4
source share
2 answers

Try registering linkbutton as asynchronous feedback control , a suitable place is the ItemCreated event that is fired on every (asynchronous / 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); } } } 
+8
source

Add this after ContentTemplate

  <Triggers> <asp:AsyncPostBackTrigger ControlID="PageEditList" EventName="ItemCommand" /> </Triggers> 
+1
source

Source: https://habr.com/ru/post/1491328/


All Articles