Creating ASP.NET Applications in Visual Studio .NET XML

ASP.NET applications require only a text editor, such as Notepad. However, creating an ASP.NET application in a text editor involves a lot of HTML and ASP.NET coding. To create ASP.NET applications easily and efficiently, you can use a tool developed by Microsoft called Visual Studio .NET.

Visual Studio .NET provides you with several features and utilities that help you create ASP.NET applications. For example, Visual Studio .NET provides you with different templates that you can use to create ASP.NET Web applications and ASP.NET Web services. In addition, you can create ASP.NET applications in any of the .NET languages, such as Visual C# and Visual Basic .NET.

In this chapter, you will create an ASP.NET Web application in Visual Basic .NET.

When you use the template that Visual Studio .NET provides to create an ASP.NET application, Visual Studio .NET creates the default classes for the application. In addition, it automatically includes the required namespaces in your application This implies that Visual Studio .NET creates a framework for the application. You can then add the code of the application to this framework.

Visual Studio .NET provides you with the color schemes for keywords and values, making them easier to read and understand. In addition, Visual Studio .NET includes an auto complete feature that completes the entries as you type the code. Visual Studio .NET also includes an auto help feature that provides instant help on any of the keywords, such as the class, event, and method names. You will learn about these and many more features of Visual Studio .NET throughout this project.

Creating a Sample ASP.NET Application

To create an ASP.NET Web application in Visual Studio .NET, perform the following steps:

  1. Launch Visual Studio .NET from the Programs menu.
  2. When you launch Visual Studio .NET for the first time, the interface for Visual Studio .NET looks like Figure.

    The Interface for Visual Studio .NET

    The Interface for Visual Studio .NET

  3. To create a new project, click on the File menu.
  4. In the list that is displayed, point to the New menu.
  5. In the displayed list, select the Project option.
  6. The New Project dialog box is displayed, as shown in Figure.
  7. The New Project Dialog Box

    The New Project Dialog Box

    As you can see, the New Project dialog box offers you various templates to create different applications.

  8. In the Project Types pane, select the Visual Basic Projects option.
  9. In the Templates pane, select the ASP.NET Web Application option.
  10. In the Location text box, type the address of the Web server on which you will develop the Web application.
  11. Note?/td>
    In our case, the development server is the local computer, so the address of the development server will appear as http://localhost/.

  12. You can also specify the name of the Web application in the Location text box.
  13. Type the name of the application as WebApplication1.
  14. Click on the OK button to create the Web application.

The Web application connects to the Web server, as shown in Figure.

The Web Application Connecting to a Web Server

The Web Application Connecting to a Web Server

The Web application opens in the Design view. The Design view of the Web application is shown in Figure.

The Design View of the Web Application

The Design View of the Web Application

Web Form

When a Web application is created, Visual Studio .NET creates a blank Web form with the name WebForm1.aspx, as shown in Figure. You can also include several Web forms in a Web application.

The Web Form that Visual Studio .NET Created

The Web Form that Visual Studio .NET Created

A Web form is a user interface for a Web application and is used to create programmable and interactive Web pages. A Web form consists of two parts: an interface that accepts user input or presents information to the user, and the code behind the interface that implements the business logic of the application. To accept input from a user, you need to include Web form controls in the Web form. The Web form controls are explained in the following section.

Web Form Controls

Visual Studio .NET provides you with several Web form controls that you can add by dragging them to the form. Web form controls contain a variety of controls that are designed to work within the ASP.NET page framework. These Web form controls are shown in Figure ASP.NET supports different types of Web form controls or server controls. Table discusses the types of Web form controls in detail.

Types of Web Form Controls

Types of Web Form Controls

Default Files in a Web Application

In addition to a Web form, Visual Studio .NET creates default files for a Web application. These default files are included in a solution.

Note?/td>

A solution is a collection of projects or related projects. For example, you can include a project and its deployment projects in the same solution.

A solution for WebApplication1 is shown in Figure.

The Default Files that Visual Studio .NET Created

The Default Files that Visual Studio .NET Created

Table discusses in detail the default files that Visual Studio .NET created.

The Default Files in a Web Application

The Default Files in a Web ApplicationThe Default Files in a Web Application

Creating an Interface for Web Application1

To create an interface for the sample Web application, you need to include an Image control, six Label controls, one Button control, five TextBox controls, and one ListBox control in the Web form. To add these controls, you need to drag them from the Web Forms toolbox and place them on the form. Next, you need to change the properties of the controls, as listed in Table.

Controls in the Web Form

Controls in the Web FormControls in the Web Form

Adding Items to the ListBox Control

As you can see, we have added a list box to the form. You can now add items to the ListBox control by performing the following steps:

  1. Click on the ListBox control to display its properties.
  2. Click on the Items property of the control to add items to the control. The ListItem Collection Editor dialog box is displayed.
  3. Click on the Add button to add an item to the list.
  4. In the Marketing Properties pane, change the following properties of the list item:
  5. Selected: True
    Text: Marketing
    Value: Marketing

  6. Similarly, add the Human Resources, Sales, Finance, and Manufacturing items to the list box.
  7. Click on the OK button to close the ListItem Collection Editor dialog box. After you have added the controls and changed their properties, the Web form should look like Figure.

The Web Form in the Design View

The Web Form in the Design View

However, the button in the Web form is not functional. To make the button functional, you need to add code to it.

Adding Code to the Submit Button

When a user enters values in the text boxes and clicks on the Submit button, the text boxes should become blank. To do this, add the following code to the Click event of the Button control:

After you have added the code to the Button control, the entire code for the application is as follows:

The code contains the declarations for all controls that you added to the Web application. In addition, the code for the Click event of the Button control is included.

Testing the Application

You can now run the application to test it. To test the application, press the F5 key. Alternatively, you can select the Start option on the Debug menu. Figure shows the Web form at runtime.

The Web Form at Runtime.

The Web Form at Runtime.

Until now, you learned to create a simple ASP.NET application. However, in most common business scenarios, the ASP.NET application needs to interact with a database. This can be achieved using the ADO.NET technology in an ASP.NET application.



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

XML Topics