# Visual Basic > Visual Basic FAQs >  ASP.Net - How do I add event handlers for the events raised by my application?

## gep13

Every control that you add to your Web Form is capable of raising events.  In order to capture these events and do something based on them occurring, you need to create an Event Handler.

Let's start with a standard ASP.Net Button.  The default event raised by this control is the click event.  The easiest way to set up the event handler for this event is to double click the button within the Design View of Visual Studio:



Once you do this, you will be taken to the Code Behind page for you application, and you will see the Click Event Handler already written out for you.

*C#*


*VB.Net*


Now that is the default Click Event now being handled, but how do you access the other Events that the Button can raise?

If you are using VB.Net, this can be done in the Code Behind View by using the two drop down lists at the top of the page.  Select the control that you are interested in the first drop down list, and then the event in the second drop down list:



In C#, this functionality if not included, however, there is an alternative, which always work in VB.Net.  Switch back to Design View, and select your Button.  Then bring up the Properties Window. (If this isn't visible, either right click on the Button and select properties, or select View | Properties Window, from the main menu).  Notice the yellow thunder bolt.  Click on this, and you will see all of the Events that can be raised by the button.  



Simply double click in the TextBox to the right of the Event that you want, and this will switch you to the Code Behind view what the event handler already stubbed out.

One important thing to note here, is that you also have the ability to select an event handler that has already been created.  Let's say you have two buttons on your page, and you want them both to use the same event handler.  For the first button, use the technique described above, however, for the second button, rather than double clicking in the Textbox for the event, only single click in it.  This will then provide a drop down list of event handlers that already exist, and you can select one to use for this second button.

So far, we have been talking about controls which are placed on your page.  However, the page itself actually also raises events.  In VB.Net, it is simple again to hook up to these events, using the two drop down list in the Code Behind view.  However, in C#, it is not immediately obvious how you can hook up these events.  Here is how this can be achieved:

 Bring your aspx page up in Visual Studio Select View | Component Designer from the Main Menu Go to your Properties Window and select the yellow thunder bolt

This will show you all the events that your page can raise, and from here you can use them as before for your controls events.

----------

