Web Server Controls

Web Server Controls

To create the ASP.NET pages you have different server controls. You can use tools that are specifically designed to work with ASP.NET 4.5 that allow you to drag and drop the controls onto a designView and change the properties of the control. You can also work with server controls directly through codeView.

Working with Server Controls on a DesignView

Visual Studio 2012 allows you to create an ASP.NET page by dragging and dropping visual controls onto a designView.

In Design view, you can place the cursor in the location where you want the control to appear and then double-click the control you want in the Toolbox window of Visual Studio.

In the Design view of your page, you can highlight a control and the properties for the control appear in the Properties window.In the below Figure, a Button control is selected in the Design View and its properties are displayed in the Properties window on the lower right corner.

Fig 1.

By Changing the properties of the highlighted control you will see the changes in the appearance of that control.

Coding Server Controls
You can also work on codeView. You will get more support in coding your applications from Visual Studio 2012. As you start typing in Visual Studio, the IntelliSense features kick in and help you with code auto-completion.

In the bellow Figure you can see an IntelliSense drop-down list which make possible code completion statements that appeared as the code was typed.

The IntelliSense focus is on the most commonly used attribute or statement for the control or piece of code that you are working with.

Fig 2.

You can also highlight a control in Source view or place your cursor in the code statement of the control, and the Properties window displays the properties of the control. You can also apply properties directly in the Properties window of Visual Studio, and these properties are automatically added to the code of your control.

ASP.NET server controls are the primary controls used in ASP.NET. These controls can be grouped into the following categories:
Validation controls – These controls are used to validate user input and they work by running client-side script.
Data source controls – These controls provides data binding to different data sources.
Data view controls – These are various lists and tables, which can bind to data from data sources for displaying.
Personalization controls – These are used for personalization of a page according to the user preferences, based on user information.
Login and security controls – These controls provide user authentication.
Master pages – These controls provide consistent layout and interface throughout the application.
Navigation controls – These controls help in navigation. For example, menus, tree view etc.
Rich controls – These controls implement special features. For example, AdRotator, FileUpload, and Calendar control.

The syntax for using server controls is:

<asp: controlType ID =”ControlID” runat=”server” Property1 =value1/>

In addition, visual studio has the following features which help in producing an error-free coding:

• By Dragging and dropping of controls onto the design view.

• By using the IntelliSense feature that displays auto-completes the properties.

• It also provides the properties window to set the property values directly.

Properties of the Server Controls
ASP.NET server controls in visual studio are derived from the WebControl class and can inherit all the properties, events, and methods of this class.

The WebControl class itself and some other server controls that are not generated are derived from the System.Web.UI.Control class. For example, PlaceHolder control or XML control.

ASP.NET server controls inherit all properties, events, and methods of the WebControl and System.Web.UI.Control class.

The following table shows the inherited properties, common to all server controls:

Scroll to Top