Login
Register
Tutorials
Forum
Career Development
Resources
Reviews
Jobs
Interview
Communities
Projects
Training
Silverlight Games
|
Bookmarks
|
New Members FAQ
|
Mentor
|
Code Converter
|
IT Companies
|
Peer Appraisal
|
Members
|
Revenue Sharing
|
Computer Jokes
|
New Posts
|
Social
|
Talk to Webmaster
Tony John
Facebook
Google+
Twitter
LinkedIn
Online Members
Devaraj T N
Phagu Mahato
Priya jain
srirama
More...
Join our online
Google+ community
for Bloggers, Content Writers and Webmasters
Forums
»
.NET
»
.NET
»
plz help me
Posted Date:
20 Nov 2007
Posted By::
Satish Kumar
Member Level:
Bronze
Member Rank:
0
Points
: 2
Responses:
2
how to detect delegate in events with example ........
Tweet
Responses
#164876 Author:
DotnetGuy
Member Level:
Gold
Member Rank:
0
Date: 20/Nov/2007 Rating:
Points
: 2
using System;
// Declare an event class.
class MyEvent {
public event EventHandler SomeEvent; // uses EventHandler delegate
// This is called to fire SomeEvent.
public void OnSomeEvent() {
if(SomeEvent != null)
SomeEvent(this, EventArgs.Empty);
}
}
public class EventDemo6 {
static void handler(object source, EventArgs arg) {
Console.WriteLine("Event occurred");
Console.WriteLine("Source is " + source);
}
public static void Main() {
MyEvent evt = new MyEvent();
// Add handler() to the event list.
evt.SomeEvent += new EventHandler(handler);
// Fire the event.
evt.OnSomeEvent();
}
}
#164882 Author:
Rupesh kumar Tiwari
Member Level:
Bronze
Member Rank:
0
Date: 20/Nov/2007 Rating:
Points
: 2
I will try to answer this...
we can make event of delegate type and publish the same event. In the subscriber page we can bind the event with the delegate which will refer to certain method which will handle the event.
ex.
//publisher page......
//declare one delegate
public delegate string HandleMyEvent(string strName);
//declare one event of delegate type
public event HandleMyEvent TellName;
protected void btn_Click(object sender, EventArgs e)
{
//publishing
if (TellName!= null)
{
TellName("Rupesh, ");
}
}
//Subscriber page....
protected void Page_Load(object sender, EventArgs e)
{
//binding the event with the delegate.
WebUserControl1.TellName+= new HandleMyEvent (TellName);
}
//Handling the event.
protected string TellName(string name)
{
name += name + "How are You!";
return name;
}
Post Reply
This thread is locked for new responses. Please post your comments and questions as a
separate thread
.
If required, refer to the URL of this page in your
new post
.
Tweet
Next :
Menu building during page load
Previous :
asp.net
Return to Discussion Forum
Post New Message
Category:
Related Messages
Is there any expert to solve this?
what is difference between String and string(data type) in c#?
what is a resource file...
Horizontal Scroll Bar for a listview control
sql querry
Follow us on Twitter:
https://twitter.com/dotnetspider
Active Members
Today
srirama
(22)
Phagu Mahato
(11)
baskar
(7)
Last 7 Days
baskar
(300)
Asheej T K
(203)
srirama
(185)
more...
Awards & Gifts
Email subscription
.NET Jobs
.NET Articles
.NET Forums
Articles Rss Feeds
Forum Rss Feeds
About Us
Contact Us
Copyright
Privacy Policy
Terms Of Use
Revenue Sharing sites
Advertise
Talk to
Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2012 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.