MrPaul Posted August 15, 2007 Posted August 15, 2007 Usually if I'm having a problem I can find others who've had the same problem, and so discover either a solution or that there is none. After a couple of hours on Google I haven't found a single person reporting this problem, which amazes me considering the simplicity of the task I am trying to perform. I have an UpdatePanel which contains a Repeater and a two LinkButton controls - one LinkButton causes an item to be added to the Repeater's data list, the other causes a random item to be removed from the list. Both these buttons work as they should, causing a partial page update which updates the UpdatePanel but does not refresh the entire page. Within the ItemTemplate of the Repeater there is a single LinkButton which when clicked, removes only that item. It's a common enough scenario: [attach]5598._xfImport[/attach] The problem is that the LinkButtons in the Repeater are not causing a partial page update (or asynchronous postback), they are causing full postbacks! I have tried everything I could think of, including: Setting ChildrenAsTriggers="false" and manually adding an AsyncPostBackTrigger for the Repeater - no change Calling ScriptManager.RegisterAsyncPostBackControl in Page_Load - no change Moving the 2 working LinkButtons outside the UpdatePanel, leaving only the Repeater - no change Placing a LinkButton inside the FooterTemplate - this also causes a full postback The fact that both of the LinkButtons outside the Repeater are working correctly indicates that the problem is not due to data binding. Code follows in the next post... Quote Never trouble another for what you can do for yourself.
MrPaul Posted August 15, 2007 Author Posted August 15, 2007 (edited) Continued... Code for previous post. XHTML: <div style="border: solid 5px green;width: 300px"> <asp:ScriptManager runat="server" ID="scriptMan" /> <asp:UpdatePanel runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"> <ContentTemplate> <asp:Repeater runat="server" ID="testRep" OnItemCommand="testRep_OnItemCommand"> <ItemTemplate> <%# Container.DataItem.ToString() %> :: <asp:LinkButton runat="server">Remove <%# Container.DataItem.ToString() %></asp:LinkButton><br /> </ItemTemplate> </asp:Repeater> <hr /> <asp:LinkButton runat="server" ID="testAdd" OnClick="testAdd_OnClick">Add New Item</asp:LinkButton><br /> <asp:LinkButton runat="server" ID="testRemove" OnClick="testRemove_OnClick">Remove Random Item</asp:LinkButton><br /> </ContentTemplate> </asp:UpdatePanel> </div> C#: public partial class ScratchPlain : System.Web.UI.Page { //Make some data static List<string> itms = new List<string>(); static int i; static ScratchPlain() { itms.Add("Item 1"); itms.Add("Item 2"); itms.Add("Item 3"); i = 4; } //Databind Repeater protected override void OnLoad(EventArgs e) { testRep.DataSource = itms; testRep.DataBind(); } //Remove clicked item - CAUSES FULL POSTBACK! protected void testRep_OnItemCommand(object sender, RepeaterCommandEventArgs e) { itms.RemoveAt(e.Item.ItemIndex); testRep.DataBind(); } //Add new item protected void testAdd_OnClick(object sender, EventArgs e) { itms.Add("Item " + (i++)); testRep.DataBind(); } //Remove random item protected void testRemove_OnClick(object sender, EventArgs e) { Random r = new Random(); itms.RemoveAt(r.Next(itms.Count)); testRep.DataBind(); } } Thanks in advance, people! :cool: Edited August 15, 2007 by MrPaul Quote Never trouble another for what you can do for yourself.
MrPaul Posted August 15, 2007 Author Posted August 15, 2007 It's all in the ID The solution to this is embarassingly simple - give the control an ID. <asp:LinkButton runat="server" ID="anything"> Works fine. Slightly annoying since I don't like to give controls an ID unless I refer to them in code, but never mind. :rolleyes: Quote Never trouble another for what you can do for yourself.
Frederick Posted September 20, 2007 Posted September 20, 2007 You are officialy my hero of the day :) Quote
jsm11482 Posted August 30, 2008 Posted August 30, 2008 Wow, that is embarrassing! I've been trying to get my UpdatePanel working for hours now! Thank you! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.