You're totally right... actually there does need to be a lot more added to your user control...
public delegate void btnWUCClickedHandler(object sender, EventArgs e);
[Category("Action")]
public event btnWUCClickedHandler btnWUCClicked;
protected virtual void OnBtnWUCClicked(EventArgs e){
if (btnWUCClicked != null){
btnWUCClicked(this, e);
}
}
protected void btnWUC_Click(object sender, EventArgs e)
{ //whatever else you want to be done in your user control
OnBtnWUCClicked(e);
}
in addition to the
btnWUC.Click += new System.EventHandler(this.btnWUC_Click);
in the page load. Then, in your default.aspx:
<SB:WebUserControl ID="btn" runat="server" OnBtnWUCClicked="btn_T"/>
----------------------------------------------------------------------------------------------------
a. Code behind of Web User Control
//Create an event handler
public event EventHandler OnButtonClick;
//Create an new event on the click of button
public void Button1_Click(object sender, EventArgs e)
{
this.OnButtonClick(this, new EventArgs());
}
b. Code behind of Web Form of ASP.NET
//On the page load event use the following code
this.WebUserControl1.OnButtonClick+=new EventHandler(WebUserControl1.OnButtonClick);
//Define the method that handles the event now
void WebUserControl1.ButtonClick(object sender, EventArgs e)
{
///custom code goes here.
}
Twitter
Facebook
Flickr
RSS
0 comments: (+add yours?)
Post a Comment