Fire WebForm Method from User Control
Basically, I would like to utilize a button inside a user control to fire a method in the parent WebForm. The code compiles, but the event never gets fired.
My User Control class is as follows:
public class ActionControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DropDownList ddlActions;
protected System.Web.UI.WebControls.Button btnGo;
public delegate void GoClickedHandler(object sender, EventArgs e);
public event GoClickedHandler GoClicked;
private void Page_Load(object sender, System.EventArgs e)
{}
public DropDownList Actions
{
get { return this.ddlActions; }
}
public Button Go
{
get { return this.btnGo; }
}
public void OnGoClicked(object sender, System.EventArgs e)
{
GoClicked(this, e);
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.btnGo.Click += new System.EventHandler(this.OnGoClicked);
this.Load += new System.EventHandler(this.Page_Load);
}
}
Then I have the following code to utilize the button in my WebForm:
ucActionControl = (ActionControl)this.LoadControl("../UserControls/ActionControl.ascx");
ucActionControl.GoClicked += new ActionControl.GoClickedHandler(this.Go_Click);
cell.Controls.Add(ucActionControl);
private void Go_Click(object sender, EventArgs e)
{
Response.Write ("EVENT IS FIRING");
}
|