ASP was primarily a linear programming model. It had six events, of which only four were commonly used. These were:
- Application_OnStart, which was fired when the application started
- Application_OnEnd, which was fired when the application terminated
- Session_OnStart, which was fired at the beginning of each session
- Session_OnEnd, which was raised when the session ended
ASP.NET, on the other hand, is primarily an event-driven programming model. The application has events, each session has events, and the page and most of the server controls can also raise events. All ASP.NET events are handled on the server. Some events cause an immediate posting to the server, while other events are simply stored until the next time the page is posted back to the server.
Because they are handled on the server, ASP.NET events are somewhat different from events in traditional client applications, in which both the event itself and the event handler occur on the client. In ASP.NET applications, however, an event is typically raised on the client, but handled on the server.
Consider a classic ASP web page with a button control on it. A Click event is raised when the button is clicked. This event is handled by the client (that is, the browser), which responds by posting the form to the server. No event handling occurs server-side.
Now consider an ASP.NET web page with a similar button control. The difference between an ASP.NET button control and a classic HTML button control is primarily that the ASP.NET button has an attribute, runat=server, that adds server-side processing to all the normal functionality of an HTML button.
When the Click event is raised, once again, the browser handles the client-side event by posting the page to the server. This time, however, an event message is also transmitted to the server. The server determines if the Click event has an event handler associated with it, and, if so, the event handler is executed on the server.
An event message is transmitted to the server via an HTTP POST. ASP.NET automagically (that's a technical term) handles all the mechanics of capturing the event, transmitting it to the server, and processing the event. As the programmer, all you have to do is create your event handlers.
Many events, such as MouseOver, are not eligible for server-side processing because they kill performance. All server-side processing requires a postback, and you do not want to post the page every time there is a MouseOver event. If these events are handled at all, it is on the client side.
One of the broad categories of controls available in ASP.NET applications is HTML server controls. These are identical to the classic HTML controls, except that they enable server-side processing. In addition, they are still used for implementing client-side event handling.
As far as ASP.NET is concerned, events are handled on the server, and the result of an event that posts back to the server is that the page is modified and redelivered to the browser.
Be the first one to add a comment