Event Handling In Asp.Net


Definition of Event Handling :
Events in ASP.NET raised at the client machine, and handled at the server machine. For example, a user clicks a button displayed in the browser. A Click event is raised. The browser handles this client-side event by posting it to the server.
The server has a subroutine describing what to do when the event is raised; it is called the event-handler. Therefore, when the event message is transmitted to the server, it checks whether the Click event has an associated event handler. If it has, the event handler is executed.
Event Arguments:

ASP.NET event handlers generally take two parameters and return void. The first parameter represents the object raising the event and the second parameter is event argument.

Application and session states:

Application state in ASP.NET is data storage available for all the classes in the application. The state has fast access over the information stored in the database. The state is applicable for all the sessions and users. 

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.



1.     Application_Start: When user starts application or a website, then the event is raised.
2.     Application_End: When user stops application or a website, then the event is raised.
Session state 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. The session state is enabled for all the variables.
The variables are saved in the SessionStateItemCollection object. The Session property is used for exposing the variables. 

      
Page and control events:

There are several page and control events in ASP.NET. They are as mentioned below:

1.     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.
2.     Init: The event is rasied when all the controls are initialized.
3.     InitComplete: The event is raised by the page object.
4.     PreLoad: The event is used to perform processing on the page or control before the execution of load event.
5.     Load: The event is raised when the control or the page is loaded.

Event handling using controls:

ASP.NET contains controls which are implemented as classes. They are associated with the events that are executed when an action is performed. There are some built in attributes and event handlers. For responding an event, a event handler is used. 

Default events

Every control inASP.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. 
Some of the controls with their default events are listed below:


1.     BulletedList control has Click as the default event
2.     AdRotator control has AdCreated as the default event
3.     CheckBox control has the CheckedChanged as the default event
4.     Calendar control has the SelectionChanged as the default event
5.     CheckBoxList has the SelectedIndexChanged as the default event
6.     DataList has the SelectedIndexChanged as the default event

Reference:



Comments

Popular posts from this blog

Top25 ASP.NET Interview Questions - FAQ | Crack the Interview Easily

State Management in ASP.Net:

The Future of .NET Developement