J
James Gerdes
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);
}
}
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);
}
}