Introduction
You've probably seen custom event arguments
in use, probably in the DataGrid section of ASP.NET. Custom event arguments
(from now on abbreviated to eventargs) allow you to create a class that you
pass along with your events that contain extra information in them that you
may want. The DataGridCommandEventArgs contains masses of information
about the DataGrid and lets you manipulate it through it. Although I won't be
showing you how to do that, this article will show you the basics of setting
up some custom eventargs and implementing them.
What are they?
Just incase you are unsure what I'm taking
about, custom eventargs are just a replacement (usually inherited from
EventArgs) for the normal EventArgs on event handlers.
eg. Instead of -
Sub MyEventHandler(ByVal
sender As
Object,
ByVal e
As
EventArgs) |
You would use -
Sub MyEventHandler(ByVal
sender As
Object,
ByVal e
As
CustomEventArgs) |
Why use them?
If you check out my
article on HTTPModules then you
will see that I use them for sending the name of the browser to the event
handler. If you have an event handler and you need to pass a lot of
information (eg. Information about a user - Name, Address, Username, password,
etc.) then this is the way.
The standard EventArgs can really only
be passed in as EventArgs.Empty ie. empty. However, the class is there
for you to be able to inherit from instead.