J
jasinx
When I run this code it creates a button on an .aspx page. When I
click the button it seems to fire the events but I'm unable to capture
them in the function in the ascx codebehind. Any help? Thank Jason.
start ASCX codebehind -------------------------------------------
public partial class WebUserControl1 : System.Web.UI.UserControl
{
Button btn = new Button();
protected override void OnInit(EventArgs e)
{
btn.Text = "this works";
btn.ID = this.UniqueID + "$btn";
btn.Click += new EventHandler(btn_Click);
base.OnInit(e);
}
protected override void Render(HtmlTextWriter writer)
{
btn.RenderControl(writer);
base.Render(writer);
}
void btn_Click(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
}
End ASCX codebehind -------------------------------------------
Start ASPX Codebehind -------------------------------------------
public partial class _Default : System.Web.UI.Page
{
WebUserControl1 ctrl;
protected void Page_Load(object sender, EventArgs e)
{
ctrl =
(WebUserControl1)LoadControl("WebUserControl1.ascx");
ctrl.ID = this.UniqueID;
Page.FindControl("divMain").Controls.Add(ctrl);
}
}
End ASPX Codebehind -------------------------------------------
click the button it seems to fire the events but I'm unable to capture
them in the function in the ascx codebehind. Any help? Thank Jason.
start ASCX codebehind -------------------------------------------
public partial class WebUserControl1 : System.Web.UI.UserControl
{
Button btn = new Button();
protected override void OnInit(EventArgs e)
{
btn.Text = "this works";
btn.ID = this.UniqueID + "$btn";
btn.Click += new EventHandler(btn_Click);
base.OnInit(e);
}
protected override void Render(HtmlTextWriter writer)
{
btn.RenderControl(writer);
base.Render(writer);
}
void btn_Click(object sender, EventArgs e)
{
throw new Exception("The method or operation is not
implemented.");
}
}
End ASCX codebehind -------------------------------------------
Start ASPX Codebehind -------------------------------------------
public partial class _Default : System.Web.UI.Page
{
WebUserControl1 ctrl;
protected void Page_Load(object sender, EventArgs e)
{
ctrl =
(WebUserControl1)LoadControl("WebUserControl1.ascx");
ctrl.ID = this.UniqueID;
Page.FindControl("divMain").Controls.Add(ctrl);
}
}
End ASPX Codebehind -------------------------------------------