Button inside update panel does not execute


Im trying to work out why a button which is within a repeater and update panel will not execute.

I have to following front end code:-

<!-- start parent repeater -->
  <asp:Repeater ID="catlist" runat="server" onitemcommand="catlist_ItemCommand" 
          onitemcreated="catlist_ItemCreated" onitemdatabound="catlist_ItemDataBound">
<asp:Label ID="lblCommentID" runat="server" Visible="false" Text='<&#37;# DataBinder.Eval(Container.DataItem, "CID") %>'></asp:Label>
  <div class="wall-container">
  <div class="wall-left">
<a href="<%# "user-wall.aspx?ID=" + Eval("UID") %>"><asp:Image ID="Image4" ImageUrl='<%# string.Format("~/avatars/{0}", Eval("Avatar")) %>' runat="server" Width="55" Height="55" BorderWidth="0px"/></a>  
  <div class="wall-right">
    <p><a href="<%# "user-wall.aspx?ID=" + Eval("UID") %>"><%# DataBinder.Eval(Container.DataItem, "Fname") %></a> 
   - <%# DataBinder.Eval(Container.DataItem, "Comment") %>
  <br />
  <small><%# DataBinder.Eval(Container.DataItem, "Added") %></small>
  <div class="comments">
    <!-- start child repeater -->
    <asp:repeater id="childRepeater" runat="server">
             <asp:Label ID="Label4" runat="server" Text="Label" Visible="false"></asp:Label>
             <div style="height:auto;margin-bottom:12px">
   <a href="<%# "user-wall.aspx?ID=" + Eval("cUID") %>"><asp:Image ID="Image5" runat="server" ImageUrl='<%# string.Format("~/avatars/{0}", Eval("cAvatar")) %>' runat="server" Width="45px" Height="45px"/></a>
      <p><a href="<%# "user-wall.aspx?ID=" + Eval("cUID") %>"><%# DataBinder.Eval(Container.DataItem, "cFname") %></a> 
   - <%# DataBinder.Eval(Container.DataItem, "cComment") %>
  <br />
  <small><%# DataBinder.Eval(Container.DataItem, "cAdded") %></small>
      <!-- end child repeater --> 

[B]      <asp:TextBox ID="TextBox2" runat="server" CssClass="text-comment" onfocus="this.value='';" 
        onblur="if (this.value=='') this.value='Write a comment';" 
        value="Write a comment" ForeColor="#A79090"></asp:TextBox>
    <asp:Button ID="Btn_ex" runat="server" Text="Submit" CommandArgument='<%# Eval("CID") %>'/>  [/B]

The code in bold is what i am referring to. Now i want to perform an action when the button is clicked. I have the code below:-

    protected void catlist_ItemCreated(object sender, RepeaterItemEventArgs e)
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            Button btn = e.Item.FindControl("Btn_ex") as Button;
            if (btn != null)
                btn.Click += new EventHandler(btn_Click);

This defines the button and below is where i perform my execution:-

    protected void btn_Click(object sender, EventArgs e)
        Button btn = sender as Button;
        if (btn != null)
            string CID = btn.CommandArgument.ToString();

            RepeaterItem item = btn.NamingContainer as RepeaterItem;
            if (item != null)
                TextBox tbox = item.FindControl("TextBox2") as TextBox;
                if (tbox != null)

But when i click the button it doesnt do anything.

Can anyone see why this is?


Happy New Year :slight_smile:

Does it work if you take the repeater out the update panel? With normal post backs? Also, get firebug installed in ur Firefox and check the console for any errors in the update panel.

Happy new year

It doesnt work if i take out the update panel. I think its because the button is within a nested repeater.

I tried setting a button click event as such:-

            &lt;asp:AsyncPostBackTrigger ControlID="Btn_ex" EventName="Click" /&gt;

But i get an error message saying:-

A control with ID ‘Btn_ex’ could not be found for the trigger in UpdatePanel ‘UpdatePanel2’.

This must be because of the nested repeaters. So i need another way to target the the button click event.

Any ideas? I do need the update panel as i need to show the users different information if they are logged in. And also how would firebug help? I do have this but dont know what im looking for…


Well, you do not need firebug if you have the error. Yea, you are right about your problem. But you shouldnt need to set an async trigger. Just the update panel to allow children as triggers. Cnt remember what exactly the tag for that is now, but it should be on by default. Your best bet would be 2 first get it working without the update panels. Just with normal postbacks, then once that is working. Add the update panels


I was just testing the code and i took the UpdatePanel out to see if the button would execute and it did. However i got an error message saying:-

Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation=“true”/> in configuration or <%@ Page EnableEventValidation=“true” %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

What does this mean?

In your page directive put EnableEventValidation=“false”. It is just saying that the validation of the event failed. This does happen from time to time.

Thank you soo much!

That was what the problem was all along


Thanks again

No problem. Glad you got it sorted