Event Handlers


We have already seen event handlers in action, but here we are going to define it properly. An event handler is basically a kind of procedure, as it is asked to do something as a result of an event, and no result will be returned by it (although if the contents of the page change as a result of the event being fired, the user will see the page in their browser change). Say, for instance, the user enters the information for sending an e-mail and then clicks the Send button. This click event will fire the OnClick event handler and ask the web server to send it out. That is, the user asks the web server to do something, and the server just does it. This matches with the definition of procedure saying that a procedure is a type of method, which would perform some kind of action but without returning any value.

The two parameters, the sender and event arguments, are required for event handler. When we click on a button and fire the OnClick event handler, the code will look like this:

Sub Button1_Click(sender As Object, e As EventArgs) End Sub

There are two arguments in this event handler. The first argument identifies the object that is raising this event, for instance, it maybe a Button, TextBox, or the Page itself. The second argument contains the event data or information related to the event handler. For example, when you click on an ImageButton, the X and Y coordinates of the point where the mouse was clicked are the information passed to the ImageButton_OnClick event handler, and can be retrieved and used in the event handler by referring to e.X and e.Y. Each argument has its data type and the compulsory parentheses are used to include the two arguments for that procedure.




Beginning Dynamic Websites with ASP. NET Web Matrix
Beginning Dynamic Websites: with ASP.NET Web Matrix (Programmer to Programmer)
ISBN: 0764543741
EAN: 2147483647
Year: 2003
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net