dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online MembersDevaraj 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 ........



Responses

#164876    Author: DotnetGuy      Member Level: Gold      Member Rank: 0     Date: 20/Nov/2007   Rating: 2 out of 52 out of 5     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: 2 out of 52 out of 5     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.



Next : Menu building during page load
Previous : asp.net
Return to Discussion Forum
Post New Message
Category:

Related Messages



Follow us on Twitter: https://twitter.com/dotnetspider

Active Members
TodayLast 7 Daysmore...

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.