I am trying to dynamically add a user control to a Custom Control that
inherits a Panel. The control renders fine on the web form. The
problem is that none of the user control's events are firing (button
clicks, etc.) on the server. The page is posting back, but none of
the user control's event delegates are being hit.
I am trying to load the User Control in the PreRender of the Custom
Control (I have tried putting this in different places with no
success).
Any help would be hugely appreciated.
Thanks,
James
Here's the code for the web form on which I'm trying to instantiate
the custom control:
public class WebForm3 : System.Web.UI.Page
{
private WebCustomControl1 cc;
private void Page_Load(object sender, System.EventArgs e)
{
//instantiate the custom panel
cc = new
WebCustomControl1("~/WebUserControl1.ascx");
//add the panel to this page's form
this.Controls[1].Controls.Add(cc);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
}
And here's the entire code for my custom control:
public class WebCustomControl1 : Panel
{
public WebCustomControl1(string url)
{
m_PlaceHolder = new PlaceHolder();
m_Url = url;
}
protected override void OnPreRender(EventArgs e)
{
this.m_PlaceHolder.Controls.Add(Page.LoadControl(m_Url));
this.Controls.Add(m_PlaceHolder);
base.OnPreRender (e);
}
}
Victor Garcia Aprea [MVP] - 25 Sep 2003 04:41 GMT
Hi James,
>>>> I am trying to load the User Control in the PreRender of the Custom
>>>> Control (I have tried putting this in different places with no
>>>> success).
That's the problem. PreRender is too late as event firing logic has already
passed by and your usercontrol didn't existed at that time. You need to add
them earlier, ie: Init.
This[1] may give you some tips.
[1] http://weblogs.asp.net/vga/posts/23498.aspx

Signature
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
> I am trying to dynamically add a user control to a Custom Control that
> inherits a Panel. The control renders fine on the web form. The
[quoted text clipped - 68 lines]
> }
> }