ASP.Net Server Controls

asplogo

Introduction:

In this article i will explain about the Server controls events in asp.net. I hope you will find it interesting. So Server Control events fall at three levels.

  • Application level
  • Page level
  • Control level

Server Control events:

When you open the web form you will find a tool box at the left side. That has different controls in it. Such as button, Textbox, drop down list. They can be divided in 3 categories.

Post back events:

Let’s first see what post back events are. Post back events are those events that make request to the   server and gets response by it. Here I ‘m going to explain it by button example. Put a button on the design view of the form. Then right click the button and press view code. Write this line in the button method

code

On clicking the button the server will respond and creating the instance of web form. Process the page and generate the html and sending it back to the client. Then destroy the form. And it will display the message Hello on the webpage.

Cached events:

Cached events are stored in the view state of the page and executed when a postback events occurs.
Like TextChanged event of text box. This can be converted into postback event by changing the AutoPostBack property to true from properties.

cached events

 

Validation events:

This event gets handled before the post back event is fired. They are placed in the toolbox, in the validation section. Suppose we want to put a validation control on the textbox. Select the requiredFiledValidator. In the properties of requiredFieldValidator  set the textbox in the ControlToValidate section.

validation events

If you don’t enter any value in the text box and fire a post back event by pressing the button. It will not proceed. As it ensures that user have to enter some value.

Article Written by Waleed Rashid. More info here.