Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Codes Author
Sat, 25-Oct-2014 Authors
All Time Authors
Satyapriyanayak
12160
Vishal@Neeraj
8240
Jayakumars
8120

Latest members | More ...


(Statistics delayed by 5 minutes)
 Codes

How to Work With Delegate and Event

Sabarimahesh
Posted by Sabarimahesh under C# on 3/16/2012 12:51:23 AM | Points: 40 | Views : 835 | Status : [Member]

using System;

using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
public delegate void delFirst(int i);
public event delFirst evenFirts;

protected void Page_Load(object sender, EventArgs e)
{
Button bt = new Button();
bt.Attributes.Add("runat", "server");
bt.Text = "EVENT";

bt.Click += new EventHandler(eventTest);
form1.Controls.Add(bt);

delFirst delF;
delF = Add;
delF += sub;

evenFirts = delF;//new delFirst(Add);
//evenFirts += delF;//new delFirst(sub);

}
public void eventTest(object sender, EventArgs e)
{
Button bt1 = (Button)sender;
bt1.Text = "Clicked";
evenFirts(5);

}

public void Add(int i)
{
Label1.Text += "From Add :" + i;


}
public void sub(int i)
{
Label1.Text += "From Sub :" + i;
}

}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M
Found interesting? Add this to:



Comments or Responses


Login to post response