Total Page Preview:   000000000681

What is event handling in ASP.NET in English and Hindi


Event handling in ASP.NET in Engilsh 

Event handling using controls in ASP.NET is a mechanism that allows you to write code that responds to events raised by controls on a web form. This includes controls such as buttons, textboxes, dropdown lists, and many others.

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.
The general syntax of an event is:
Application and Session Events
The most important application events are:
  • Application_Start - It is raised when the application/website is started.
  • Application_End - It is raised when the application/website is stopped.
Similarly, the most used Session events are:
  • Session_Start - It is raised when a user first requests a page from the application.
  • Session_End - It is raised when the session ends.
Page and Control Events
Common page and control events are:
  • DataBinding - It is raised when a control binds to a data source.
  • Disposed - It is raised when the page or the control is released.
  • Error - It is a page event, occurs when an unhandled exception is thrown.
  • Init - It is raised when the page or the control is initialized.
  • Load - It is raised when the page or a control is loaded.
  • PreRender - It is raised when the page or the control is to be rendered.
  • Unload - It is raised when the page or control is unloaded from memory.
Event Handling Using Controls
All ASP.NET controls are implemented as classes, and they have events which are fired when a user performs a certain action on them. For example, when a user clicks a button the 'Click' event is generated. For handling events, there are in-built attributes and event handlers. Event handler is coded to respond to an event, and take appropriate action on it.
By default, Visual Studio creates an event handler by including a Handles clause on the Sub procedure. This clause names the control and event that the procedure handles.
The ASP tag for a button control:
The event handler for the Click event:
An event can also be coded without Handles clause. Then, the handler must be named according to the appropriate event attribute of the control.
The ASP tag for a button control:
The event handler for the Click event:
The common control events are:
Some events cause the form to be posted back to the server immediately, these are called the postback events. For example, the click event such as, Button.Click.
Some events are not posted back to the server immediately, these are called non-postback events.
For example, the change events or selection events such as TextBox.TextChanged or CheckBox.CheckedChanged. The nonpostback events could be made to post back immediately by setting their AutoPostBack property to true.
Default Events
The default event for the Page object is Load event. Similarly, every control has a default event. For example, default event for the button control is the Click event.
The default event handler could be created in Visual Studio, just by double clicking the control in design view. The following table shows some of the default events for common controls:


Event handling in ASP.NET in Hindi 

Event handling me ek programming technique hai jismein hum kisi control ke events (jaise ki button click, page load, etc.) ko handle karte hain aur uske liye code likhte hain. Event handling me bahut important hai kyunki ye user interface interactions ke sath sath data ko bhi handle karta hai.
Ek example ke roop mein, maan lijiye ki humare paas ek web form hai jismein ek button control hai jiska ID "btnSubmit" hai. Hum iss button ka click event handle karna chahte hain, jisse ki jab user iss button ko click kare, hum uske dwara submit kiye gaye data ko handle kar sakein.
ASP.NET me, hum "OnClick" event ka upyog karte hain jisse ki hum iss button ke click event ko handle kar sakein. Neeche diye gaye code snippet me, humne "OnClick" event ke sath ek function ko attach kiya hai jiska naam "btnSubmit_Click" hai:
Ab hum iss function ko define karte hain jisse ki jab user "btnSubmit" button ko click kare, ye function call ho jaye. Neeche diya gaya code snippet ek example hai jismein "btnSubmit_Click" function "Label1" control ko update karta hai.
Iss example me, "btnSubmit_Click" function "object sender" aur "EventArgs e" parameters leta hai jinhe hum iss function me use kar sakte hain. Humne iss function me "Label1" control ko update karne ke liye "Text" property ka upyog kiya hai. Jab user "btnSubmit" button ko click karega, ye function call hoga aur "Label1" control me "You clicked the submit button!" ka text show hoga.

Thank You

About Author

Brijesh Kumar

Database Developer

I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall and Database Migration On-Premise to Azure Cloud.
LinkedIn :





Facebook User: