Definition of Event Handling In Asp.Net:
The events are raised by the client. The server handles all the event requests. If the user presses a key, the key press event is raised. The server handles the key press event. The Event handler is a subroutine it is defined at the server end. The actions to be performed when an event is raised are defined in the handler.The event is raised by the client and the server checks for the availability of the appropriate handler in Asp.Net . If the corresponding event is present, the event handler is executed.
Event Handling always take two parameters and return void. The first parameter represents the object raising the event and the second parameter is event argument.
The syntax for an event is:
private void EventName( object sender, EventArgs e );
- Object sender represents the object raising the event
- EventArgs represents the event arguments
Application And Sessions State:
Application state is data storage available for all the classes in the application. The state has fast access over the information stored in the database.Application state is saved in an instance of HttpApplicationState class.
The instance is created when the user first time accesses the resources. The state is saved in the memory of the server. Hence, it is lost when user closes or restarts the application. The application state is not used by multiple servers in the same application. The application data can be used by many threads. The synchronization is must during the access of information from the application state.
- Application_Start– It is raised when the application or website is started.
- Application_End– It is raised when the application or website is stopped.
Session state is defined as to helps user store and access values from the user as user navigates the pages in an application. The state checks for the requests from the browser in a limited span of time. Generally the session state is enabled for all the variables.
The variables are saved in the SessionStateItemCollection object.
Page and Control Events :
The mainly used page and control events are,given below
- Load: The event is raised when the control or the page is loaded.
- InitComplete: The event is raised by the page object.
- Ini t: The event is rasied when all the controls are initialized.
- PreLoad: The event is used to perform processing on the page or control before the execution of load event.
- PreInit : The event is used for recreation of dynamic controls, setting the master page and the theme property, get or set the profile values, verify the IsPostBack property.
Every control in ASP.NET has a default event associated with it. The event handler can be created in the Visual Studio application. User needs to double click on the control present in the design view.
Few of the controls with their default events are given below,
- Calendar control has the SelectionChanged as the default event.
- Button Control has Click as the default event.
- AdRotator control has AdCreated as the default event.
- BulletedList control has Click as the default event.