Why my button doesn't do a postback?

Posted on 2008-11-07
Last Modified: 2012-05-05
Hi experts!
I've a Web User Control that contain a "Panel" inside this panel there is a button.The button have an event in the server side called Button1_Click.

Also I've a page, in which I am calling a Collapsible panel Extender from the server side.One of the properties of this Collapsible panel Extender is to have a TargetControlID, this TargetControlID need to be a "Panel".  I am targetting the "Panel" from my Web User Control. This work fine and show the panel...BUT

The button inside the panel have lost the event. The event Button_click is not trigerring at all....
WHY?????.....I am attaching my code with comments

Ps: So far I have publish a question like this for 3 days and nobody have found an answer.....

This is the web user control .ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Exampletry.ascx.cs" Inherits="controls_Exampletry" %>

<asp:Panel ID="ContentPanelStep" runat="server">   // the panel which it is going to be the TargetID for the collapsiblePanel

   <asp:Button ID="Button1" runat="server" Text="Testing" OnClick="Button1_Click" />       //The button  is inside the Panel with an event, this button is the one that is triggering.


This is the web user control ascx.cs:

public partial class controls_Exampletry : System.Web.UI.UserControl


    protected void Page_Load(object sender, EventArgs e)



    protected void Button1_Click(object sender, EventArgs e)


              //This is the event that is not triggering


    public Panel StepPanel


        get { return ContentPanelStep; }  //this is my panel and inside this panel there is a button. I make it public so I can call it for the aspx. page



This is my code in my page:

    protected void Page_Load(object sender, EventArgs e)


     controls_Exampletry myControl = (controls_Exampletry)Page.LoadControl("controls/Exampletry.ascx");  //Loading hte WebUserControl into am object called mycontrol

      myControl.ID= = "MyControl1"; //Seting and ID for this object

      HtmlTableRow stepRow = new HtmlTableRow();      //This is a dynamic Row

      HtmlTableCell stepCell = new HtmlTableCell();        //This is a dynamic Cell

     AjaxControlToolkit.CollapsiblePanelExtender cpe1 = new AjaxControlToolkit.CollapsiblePanelExtender();    //creating the Collapsible Panel from server side and give it an instance or object


     cpe1.ID = "CollapsiblePanelExtender";   // giving an ID to the Collapsible Panel

     cpe1.TargetControlID = myControl.StepPanel.UniqueID;

                     //This is the line that I think is the problem, I am callling the ID for the panel that is contained in the web  user control . I tried ClientID and it didn't work neither. I can see the panel with the button but the event from that button inside that panel is not triggering.  




        StepsTable.Rows.Add(stepRow);      //I have a table with ID=StepsTable that will received this adding of the row


Open in new window

Question by:eddyperu
    LVL 7

    Expert Comment

    Can you move the code to the Page_Init event handler?
    LVL 4

    Author Comment

    I did it ...and it didn't work neither :(
    LVL 4

    Accepted Solution

    I found the answer I publish it here just in case someone else is looking for this:
            controls_Exampletry myControl = (controls_Exampletry)Page.LoadControl("controls/Exampletry.ascx");
            myControl.ID = "MyControl1";
            controls_NewHireWorkflowStepControl myHeaderControl = (controls_NewHireWorkflowStepControl)Page.LoadControl("controls/NewHireWorkflowStepControl.ascx");
            myHeaderControl.ID = "MyHeaderControl1";

            AjaxControlToolkit.CollapsiblePanelExtender cpe1 = new AjaxControlToolkit.CollapsiblePanelExtender();
            cpe1.ID = "myCollapsiblePanelExtender";
            // cpe1.TargetControlID = Page.FindControl(myControl.ID).StepPanel.ID;
            cpe1.TargetControlID = myControl.StepPanel.UniqueID;
            cpe1.ExpandControlID = myHeaderControl.StepHeaderPanel.UniqueID;
            cpe1.CollapseControlID = myHeaderControl.StepHeaderPanel.UniqueID;
            cpe1.BehaviorID = "CPEBehavior";
            cpe1.Collapsed = true;
            cpe1.AutoCollapse = false;
            cpe1.AutoExpand = false;
            cpe1.ScrollContents = false;
            cpe1.ExpandDirection = AjaxControlToolkit.CollapsiblePanelExpandDirection.Vertical;


            HtmlTableRow stepRow = new HtmlTableRow();
            HtmlTableCell stepCell = new HtmlTableCell();

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now