ASP.NET Forms Building with webcontrols part two

6:59 PM Posted by Isha

Building forms with ASP.NET with web controls is introduced in the previous post and here is the continuation for that.

Web Forms components

An ASP.NET Web Forms page consists of a user interface and programming logic. The user interface helps display information to users, while the programming logic handles user interaction with the Web Forms pages. The user interface consists of a file containing a markup language, such as HTML or XML, and server controls. This file is called a page and has .aspx as its extension.

The functionality to respond to user interactions with the Web Forms pages is implemented by using programming languages, such as Visual Basic .NET and C#. You can implement the programming logic in the ASPX file or in a separate file written in any CLR-supported language, such as Visual Basic .NET or C#. This separate file is called the code behind file and has either .aspx.cs or .aspx.vb as its extension depending on the language used. Thus, a Web Forms page consists of a page (ASPX file) and a code behind file (.aspx.cs file or .aspx.vb file).

Web Forms server controls

You can design a Web Forms page by using controls called Web Forms server controls.
You can program the functionality to be provided for the server controls. The server controls are different from the usual Windows controls because they work within the ASP.NET Framework. The different types of server controls are described as follows:

HTML server controls:

These controls refer to the HTML elements that can be used in server code. The HTML elements can be converted into HTML server controls. To do so, you need to use attributes, such as ID and RUNAT, in the tags that are used to add the HTML controls.

ASP.NET server controls:

These controls do not map one-to-one to HTML server controls. ASP.NET server controls include traditional form controls, such as text boxes and buttons, and complex controls, such as tables.

Validation controls:

These controls are used to validate users' input.

Validation controls can be attached to input controls to check the values entered.

User controls: These controls are created from the existing Web Forms pages and can be used in other Web Forms pages.

Creating Web Forms Application Projects

Before you use any server control to design a Web Forms page, you need to create an ASP.NET Web Application project. You can create either a Visual Basic .NET or a C# Web Application project, depending on the programming language you want to use. A Web Application project is always created on a Web server.

When you create a Web Application project, the Application Wizard creates the necessary project files along with the page file and code behind class file as described:

WebForm1.aspx:

This page file consists of the user interface for the visual representation of the Web Forms page. The file has two views, Design and HTML. The default view is Design view.

Design view:

This view represents the user interface for the Web Forms page. You can place controls directly from the toolbox to the Web Forms page in Design view. By default, the page layout of the Web Forms page is GridLayout. This layout enables you to accurately position controls on the page by using the absolute coordinates (X,Y) of the page. In addition to GridLayout, ASP.NET provides another page layout, which is called FlowLayout.

In FlowLayout, you can add text to the page directly in Design mode. You can change the page layout from the default GridLayout to FlowLayout. To do so, right-click the page in Design view and select Properties from the context menu. Next, in the DOCUMENT Property Pages dialog box, from the Page Layout list box, select FlowLayout.

HTML view:

This view represents the ASP.NET code for the Web Forms page. To open HTML view, click the HTML tab in the designer. When the Web Application project is a Visual Basic project or a C# project, the scripting language used in the HTML page is Visual Basic or C#, respectively.


WebForm1.aspx.cs or WebForm1.aspx.vb:

This file consists of the code to implement programming logic in the Web Forms page. You can view the code file by using the Show All Files icon in the Solution Explorer window. If the Web Application project is a Visual Basic project, you use Visual Basic .NET to implement the programming logic and the code file is called the WebForm1.aspx.vb file. Conversely, if the Web Application project is a C# project, you use C# to implement the programming logic and the code file is called the WebForm1.aspx.cs file.

0 comments:

Post a Comment