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.
</asp:Panel>
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.
stepCell.Controls.Add(myControl);
stepCell.Controls.Add(cpe1);
stepRow.Cells.Add(stepCell);
StepsTable.Rows.Add(stepRow); //I have a table with ID=StepsTable that will received this adding of the row
}
Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.
When asked, what has been your best career decision?
Deciding to stick with EE.
Being involved with EE helped me to grow personally and professionally.
Connect with Certified Experts to gain insight and support on specific technology challenges including:
We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE