The Web Forms Events Model



Because of the disconnected nature of the Web, the events raised in ASP.NET Web Forms function differently from events in standard Windows GUI applications.

This is because the events are fired within the client browser but are transferred to the web server via an HTTP POST. There they are handled by the ASP.NET page framework.

The ability of the ASP.NET runtime server engine to handle events raised on the client significantly simplifies the development of interactive web applications. You develop your event-handling routines in the same way as you do in Windows Forms applications.

Because the server is remote (and events need a round trip to the server), the performance of event handling suffers.
Many mouse-moving events, which have to tie into server code, are not practical in a web model. So the number of built-in events on offer is limited.

However, server controls generally offer an event to signal that their contents have changed. For instance, TextBox has a TextChanged event and CheckBox has a CheckChanged event.

The handling of these events is postponed until the next round trip to the server. The specific part of the event-management model where events are captured on the client and are sent together to the server via a single HTTP POST is called the postback event model.

Some higher-level events are raised by ASP.NET. These include session events and application events.

The user-session events are Start, indicating the start of an application session, and End, meaning the end or timeout of a session.

The Application object offers many public events such as BeginRequest and EndRequest, indicating the start and the end of an HTTP request associated with a web application.

Handlers for the session and application events are coded in the Global.asax page.