Export (0) Print
Expand All
3 out of 7 rated this helpful - Rate this topic

Creating Event Handlers in Web Forms Pages

Controls have a default event, which is the event most commonly associated with that control. For example, the default event for a button is the click event. You can create event handlers for both the default event and other events; however, the procedure is different for each type of event.

To create the event handler for a default event

  • In Design view of the Web Forms Designer, double-click the control or page.

    The Code Editor opens with the insertion point in the event handler.

There is a different process for creating a handler for non-default events. The process differs for Visual Basic and Visual C#, due to slight differences in the Web Forms Designer user interface for those languages.

To create an event handler for non-default events in Visual Basic

  1. Open or switch to the Code Editor for the page.
  2. At the top of the window, select the control from the left-hand drop-down list, and select the event from the right-hand drop-down list.
    Note   Events for which methods already exist are displayed in bold.

    The event handler is created.

    Visual Basic creates an event handler and adds it to your form's class.

To create an event handler for non-default events in Visual C#

  1. In Design view, select the control, and then press F4 to display the Properties window.
  2. In the Properties window, click the Events button (6w2tb12s.vxeventsbutton_propertieswindow(en-us,VS.71).gif).

    The Properties window displays a list of the events for the control, with boxes to the right that display the names of event handlers bound to those events.

  3. Locate the event you want to create a handler for and then:
    • In the event name box, type the name of an event handler.

    -or-

    • Double-click the event name box to create a handler whose name follows the convention controlID_eventname.

    The new event handler is created with the name you typed or with the generated name.

See Also

Binding to an Existing Event Handler in Web Forms Pages | Creating an Event Handler at Run Time in Web Forms Pages | Connecting Multiple Events to a Single Event Handler in Web Forms Pages | ASP.NET Server Control Event Model | Handling and Raising Events | Server Event Handling in Web Forms Pages | ASP.NET Server Controls

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.