Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to implement a generic event handling routine in asp.net c# that takes any control as an input and performs the required operation?That is how to implement ROUTINES for controls having similar operations?
Posted

1 solution

Every event is generic already (barring only the "specialised" ones with custom EventArgs, and even they will work with the base version) since they provide a sender object parameter which is the class (or Control in this case) that raised the event and an e EventArgs parameter with any details. So you can (in theory, I'd hate to do it in practice) send all your Events to a single handler, and sort out within that what the handler is supposed to do with it.

Probably be a poor way to handle things if you are expecting a number of different Control types to use the same handler though - but it is possible.
 
Share this answer
 
Comments
SubhamSoni123 25-Sep-13 11:45am    
If i set of button events i want a single code to handle them generically rather than seperate group of codes and what is the substitute of dll in a web page?
OriginalGriff 25-Sep-13 12:01pm    
A set of buttons can all use the same handler method, yes - no problem at all, I do it all the time.
The substitute for "a DLL file" in a web page is "a DLL file". They work fine, as long as you add a reference to the file.
SubhamSoni123 25-Sep-13 12:04pm    
But dll's are only for windows applications right?
OriginalGriff 25-Sep-13 12:53pm    
Good grief no!
.NET works with two types of executable files: EXE and DLL - they both contain Assemblies, and the only practical difference is that a DLL does not contain a "main" method.
The whole of .NET that supports your web site is in DLL files! :laugh:
SubhamSoni123 25-Sep-13 22:05pm    
So now can I write my Generic Event Handling routines in dll's and call them?If so can please tell how to implement?

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