Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am Mani, Studying MCA. I new to the dotnet. I read so many articles on delegates and events in csharp i understand the concept. I know how to use it. But i dont know where can i use delegates and events in asp.net. i totally confused in that topic. Any one send some samples on this topics using asp.net and c sharp with code.

Regards,
G.Manikanta
Posted
Updated 7-May-11 20:58pm
v2
Comments
Sergey Alexandrovich Kryukov 8-May-11 2:59am    
Replace tag from APS.NET to .NET. ASP.NET is irrelevant to this fundamental question.
--SA

1 solution

You can use delegates whenever you can use events. I'm not considering the cases where you're already bound to use events because of the library you use.

So, why using events at all? They essentially do what an delegate instance can do but introduce a number of limitations. It makes programming safer. In particular, the event can only be fired in the class where it is declared. For that reason events are used for event-oriented UI and represent Windows messages, for example.

Delegate is more basic concept than the event. Whenever you work with event (add a handler to it), a delegate instance is involved, but the delegates can be used without events.

Warning! One typical misconception is that events are multicast while delegates are not. This is not true. A delegates instance becomes multicast as soon as more than one event handler is added to its invocation list. Another misconception is that events require limitation of using System.EventArguments and derived classes with System.EvenHandler (generic or not). This is only a Microsoft recommendation, which I recommend to follow in all cases though. A failure to follow this recommendation is detected by FxCop but not compiler. There are no any special recommendations for delegates.

For more information, see http://msdn.microsoft.com/en-us/library/17sde2xt.aspx[^].

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900