ASP Versus ASP.NET Events
By: Dan Hurwitz and Jesse Liberty in Asp.net Tutorials on 2009-02-27
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.
If you want a client-side event handler to perform scripted functions, you must supply your own scripting in either JavaScript or VBScript called from the appropriate event handler. For this to work properly, the client browser must support scripting.
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.
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- Android
- React Native
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Things to note when changing a function to async in your controller
AmbiguousMatchException: The request matched multiple endpoints.
Call an Action in a controller when user clicks a button in View
Button that is only clickable when the checkbox is checked
Pass the same model to multiple views within the same controller
Passing a model globally to all Views in your Asp.net webapp
Pagination in ASP.net core application
Microsoft.Identity vs Microsoft.IdentityModel.Clients.ActiveDirectory
Comments