This is a content page Mypage.aspx from my MasterPage
controls_Exampletry
myControl = (controls_Exampletry)Page.LoadControl("controls/Exampletry.ascx"); //loading a
web user control that contain a panel inside this object
AjaxControlToolkit.
CollapsiblePanelExtender cpe1 =
new AjaxControlToolkit.CollapsiblePanelExtender();
cpe1.ID = "CollapsiblePanelExtender";
cpe1.TargetControlID = myControl.StepPanel.ClientID; //This is the line that have the problem, It doesn't want to find the clientID...why?
Web user Control Exampletry.ascx:
public
Panel StepPanel
{
get { return ContentPanelStep; } //This is just the ID of my panel
}
The error says this: Exception Details: System.InvalidOperationException: The TargetControlID of 'CollapsiblePanelExtender' is not valid. A control with ID 'MyControl1_ContentPanelStep' could not be found.
Are you adding your user control to the Page's control collection after loading it? If you don't do that, then it won't be rendered and won't have a ClientID or a UniqueID. Alternatively, you can try setting the TargetControID property with the user control
panel's ID and then add the CollapsiblePanelExtender and the user control to the Page Controls collection and see if it works.
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
}
First off, I'd suggest that you move your control loading code to the Page Init or the Page PreRender method instead of the Page Load method, like this:
protected void Page_Init(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
HtmlTable StepsTable = new HtmlTable(); 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 stepCell.Controls.Add(myControl);
stepCell.Controls.Add(cpe1);
cpe1.ID = "CollapsiblePanelExtender"; // giving an ID to the Collapsible Panel cpe1.TargetControlID = myControl.StepPanel.ID; //If the above line gives a problem, then try saying stepCell.FindControl(myControl.ID).ID
stepRow.Cells.Add(stepCell); StepsTable.Rows.Add(stepRow); //I have a table with ID=StepsTable that will received this adding of the row }
Lastly, in your case there are many complications like dynamically adding extenders (not just controls), dynamically adding user controls, trying to ask the extender to access a control inside the user control and many other things. So, I'm not sure whether the above code would still start working from the word go. So, you can keep posting your responses here, if things don't work.
Exception Details: System.InvalidOperationException: The TargetControlID of 'CollapsiblePanelExtender' is not valid. A control with ID 'ContentPanelStep' could not be found.
protected void Page_Init(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
Page.Controls.Add(myControl);
AjaxControlToolkit.CollapsiblePanelExtender cpe1 = new AjaxControlToolkit.CollapsiblePanelExtender(); //creating the Collapsible Panel from server side and give it an instance or object cpe1.ID = "myCollapsiblePanelExtender"; // giving an ID to the Collapsible Panel cpe1.TargetControlID = myControl.StepPanel.ID; //If the above line gives a problem, then try saying cpe1.TargetControlID = Page.FindControl(myControl.ID).ID
Page.Controls.Add(cpe1);
HtmlTable StepsTable = new HtmlTable(); HtmlTableRow stepRow = new HtmlTableRow(); //This is a dynamic Row HtmlTableCell stepCell = new HtmlTableCell(); //This is a dynamic Cell
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 }
Using this line : cpe1.TargetControlID = mycontrol.StepPanel.ID
Give this error:
Exception Details: System.InvalidOperationException: The TargetControlID of 'myCollapsiblePanelExtender' is not valid. A control with ID 'ContentPanelStep' could not be found.
Using this line: cpe1.TargetControlID = Page.FindControl(myControl.ID).ID;
Give me this error:
Exception Details: System.InvalidOperationException: Extender control 'myCollapsiblePanelExtender' cannot extend 'MyControl1'. Extender controls of type 'AjaxControlToolkit.CollapsiblePanelExtender' cannot extend controls of type 'ASP.controls_exampletry_ascx'.
When I set this update panel in the Web use control I have this error, do you know why??
Exception Details: System.ArgumentException: Cannot unregister UpdatePanel with ID 'UpdatePanel1' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and
later added again, which is not supported.
Parameter name: updatePanel
eddyperu1
Member
6 Points
17 Posts
Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 06, 2008 08:12 PM|LINK
This is a content page Mypage.aspx from my MasterPage
controls_Exampletry
myControl = (controls_Exampletry)Page.LoadControl("controls/Exampletry.ascx"); //loading a web user control that contain a panel inside this objectAjaxControlToolkit.
CollapsiblePanelExtender cpe1 = new AjaxControlToolkit.CollapsiblePanelExtender();cpe1.ID = "CollapsiblePanelExtender";
cpe1.TargetControlID = myControl.StepPanel.ClientID; //This is the line that have the problem, It doesn't want to find the clientID...why?
Web user Control Exampletry.ascx:
public Panel StepPanel{
get { return ContentPanelStep; } //This is just the ID of my panel}
The error says this: Exception Details: System.InvalidOperationException: The TargetControlID of 'CollapsiblePanelExtender' is not valid. A control with ID 'MyControl1_ContentPanelStep' could not be found.
C#
tejpalthatte
Member
692 Points
126 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 06, 2008 08:33 PM|LINK
Are you adding your user control to the Page's control collection after loading it? If you don't do that, then it won't be rendered and won't have a ClientID or a UniqueID. Alternatively, you can try setting the TargetControID property with the user control panel's ID and then add the CollapsiblePanelExtender and the user control to the Page Controls collection and see if it works.
eddyperu1
Member
6 Points
17 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 07, 2008 01:53 PM|LINK
Would you mind to send me an example anbout this with my code. I am sore it of new in C#
Thank you so much for your help
eddyperu1
Member
6 Points
17 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 07, 2008 01:56 PM|LINK
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 }tejpalthatte
Member
692 Points
126 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 07, 2008 02:58 PM|LINK
First off, I'd suggest that you move your control loading code to the Page Init or the Page PreRender method instead of the Page Load method, like this:
eddyperu1
Member
6 Points
17 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 07, 2008 03:10 PM|LINK
I have this error:
Exception Details: System.InvalidOperationException: The TargetControlID of 'CollapsiblePanelExtender' is not valid. A control with ID 'ContentPanelStep' could not be found.
tejpalthatte
Member
692 Points
126 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 07, 2008 03:27 PM|LINK
eddyperu1
Member
6 Points
17 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 07, 2008 03:44 PM|LINK
Using this line : cpe1.TargetControlID = mycontrol.StepPanel.ID
Give this error:
Exception Details: System.InvalidOperationException: The TargetControlID of 'myCollapsiblePanelExtender' is not valid. A control with ID 'ContentPanelStep' could not be found.
Using this line: cpe1.TargetControlID = Page.FindControl(myControl.ID).ID;
Give me this error:
Exception Details: System.InvalidOperationException: Extender control 'myCollapsiblePanelExtender' cannot extend 'MyControl1'. Extender controls of type 'AjaxControlToolkit.CollapsiblePanelExtender' cannot extend controls of type 'ASP.controls_exampletry_ascx'.
The code:
protected void Page_Init(object sender, EventArgs e){
controls_Exampletry myControl = (controls_Exampletry)Page.LoadControl("controls/Exampletry.ascx");myControl.ID = "MyControl1";Page.Controls.Add(myControl);
AjaxControlToolkit.
CollapsiblePanelExtender cpe1 = new AjaxControlToolkit.CollapsiblePanelExtender(); cpe1.ID = "myCollapsiblePanelExtender"; //cpe1.TargetControlID = Page.FindControl(myControl.ID).ID;cpe1.TargetControlID = myControl.StepPanel.ID;
Page.Controls.Add(cpe1);
HtmlTableRow stepRow = new HtmlTableRow();HtmlTableCell stepCell = new HtmlTableCell();stepCell.Controls.Add(myControl);
stepCell.Controls.Add(cpe1);
stepRow.Cells.Add(stepCell);
StepsTable.Rows.Add(stepRow);
}
tejpalthatte
Member
692 Points
126 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 07, 2008 03:48 PM|LINK
Try this line:
cpe1.TargetControlID = Page.FindControl(myControl.ID).StepPanel.ID;
eddyperu1
Member
6 Points
17 Posts
Re: Why my collapsible Panel doesn't read the ClientID from my web User Control?
Nov 07, 2008 03:55 PM|LINK
I add your line and there is an error that says
System.web.UI.Control does not contain a definition for 'StepPanel'
But then I try this:
cpe1.TargetControlID = myControl.StepPanel.UniqueID;
and it is working :):) BUt to make this line work I sacrificed the update panel from my web use control.
<%
@ Control Language="C#" AutoEventWireup="true" CodeFile="Exampletry.ascx.cs" Inherits="controls_Exampletry" %><
asp:Panel ID="ContentPanelStep" runat="server"> <asp:UpdatePanel runat="server" ID="UpdatePanel1"> <ContentTemplate> <asp:Button ID="Button1" runat="server" Text="Testing" OnClick="Button1_Click" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> </Triggers> </asp:UpdatePanel></
asp:Panel>When I set this update panel in the Web use control I have this error, do you know why??
Exception Details: System.ArgumentException: Cannot unregister UpdatePanel with ID 'UpdatePanel1' since it was not registered with the ScriptManager. This might occur if the UpdatePanel was removed from the control tree and later added again, which is not supported.
Parameter name: updatePanel