public delegate void OnButtonClick(string val);
public event OnButtonClick eventHandler;
protected void Page_Load(object sender, EventArgs e){
}
protected void Button1_Click(object sender, EventArgs e){
if (eventHandler != null)eventHandler(
"Add");
// var classname = eventHandler.Method.DeclaringType;Response.Write("Added");
// Response.Write("Added " + classname);//eventHandler = null;}
protected void Button2_Click(object sender, EventArgs e){
if (eventHandler != null)eventHandler(
"Update");Response.Write(
"updated");
//eventHandler = null;}
protected void Button3_Click(object sender, EventArgs e){
if (eventHandler != null)eventHandler(
"Delete");Response.Write(
"Deleted");
//eventHandler = null;}
}
In ASPX page, take two pages say, Default.aspx and Home.aspx :
Use this usercontrol in both the pages.
Default.aspx
.......
</head><
body><form id="form1" runat="server"><div>
<USC1:UserControl runat="server" ID="Direct" EnableTheming="True" />..........
..........
</div></form></
body></
html>
Code Behind :
public partial class _Default : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e){
if(Page.IsPostBack)Direct.eventHandler +=
new ButtonCombo.OnButtonClick(Direct_eventHandler);
}
void Direct_eventHandler(string val){
//val = "Hello";//Label1.Text=val;Response.Write("Operation : " +val);
}
}
Similarly in HOME.ASPX, use this usercontrol and write the similar event:
Home.Aspx :
public partial class Home : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
if (Page.IsPostBack)Usc1.eventHandler +=
new ButtonCombo.OnButtonClick(Direct_eventHandler);}
void Direct_eventHandler(string val){
//val = "Hello";//Label1.Text = val;Response.Write(val + "In new page");}
}
The Output of the Default page:
The Output of the Home page:
No comments:
Post a Comment