2.5 introduction to Visual Studio. NET

Source: Internet
Author: User

Visual Studio. NET into. NET) is the latest integrated development environment launched by Microsoft, which integrates source program editing, compilation, linking, project management, and program release. It has powerful functions. It supports multiple languages, including VB. NET, C #, C ++, and C ++. NET. The main interface of VS. NET is 2-12.
The main steps for designing ASP. NET Applications in VS. NET are as follows:
◆ Create a project corresponding to the ASP. NET application;
◆ Use visual controls of VS. NET to design the application interface with multiple pages );
◆ Compile the Event code of the application control. One interface can contain multiple controls and compile the required Event code ).

Figure 2-12 VS. NET Main Interface

The following example shows how to design an ASP. NET application in VS. NET.

Example 2.2: design the data input interface 2-13 in VS. NET. When you press the "Submit" button, the user input information is displayed on the new page 2-14 ).

Figure 2-13 Information Input page

Figure 2-14 displays user input information


The procedure is as follows:
1) create a project. In. in the NET main menu, select "file" target "" project ". The" new project "dialog box shown in 2-15 is displayed. In" location L) "Enter the location information for the project in the displayed text box, in this example enter" http: // localhost/Ex2-2 ", click OK,. NET will create a project named Ex2-2, as shown in 2-16, where a file named Webform1.aspx will be automatically created, which is the home page file of the project that can change the default file name Webform1.aspx in solution manager ). The home page is the first page displayed when you run the program.
This example contains two pages: the home page and the information display page. The name of the home page is Webform1.aspx. The information display page is the content you enter in the "name" and "Age" on the home page, select "gender", click "Submit", and the server returns the page to the browser. The file name is set to display. aspx.

Figure 2-15 "new project" dialog box

Figure 2-16 VS. NET


If there are multiple pages in the project, the designers must add all the page files except the homepage files that are automatically generated when the project is created. To add a page file to a project, right-click the project name in the solution manager window, in the shortcut menu shown in 2-17, select "add"-"Add new item". The "Add new item" dialog box shown in 2-18 appears. Enter the new page file name, as shown in 2-18 ).

Figure 2-17 Add a new item to the Project

Figure 2-18 input page file name


Next, add the control to the application interface and edit its properties.
2) use the related controls in the VS. NET toolbox to design the application interface.
To add a server control to the application interface, move the mouse to the toolkit icon and open toolkit 2-19.) Select HTML control, Web control, and data control ), in the control toolbox, select the desired control and drag it to the interface. For example, to add a TextBox text box to Webform1.aspx, you can open the Web server control toolbox, select the TextBox Control, drag it to the appropriate position of the page corresponding to Webform1.aspx, and release the mouse button.

Figure 2-19 toolbox


To set the control properties, select the control to be edited in the page file. A box with a selected flag appears around the control, as shown in 2-20 (B ), then, set the attribute value in the Attribute Editor window. For example, to set the ID attribute value of the selected TextBox Control to "TxtName", you can find the "ID)" attribute name in the "properties" window, enter the "TxtName" string in the text box on the right, as shown in 2-21 ).

Figure 2-20 two states of the control

Figure 2-21 Edit Control Properties

Some controls have sub-menus. For example, most HTML controls have style attributes. You must set each sub-menu to complete the settings. In this example, the "Title" Label control in Webform1.aspx is used to display the Title.) To set the style attribute, click the button in the text box on the right of the "style" attribute, the style generator dialog box shown in Figure 2-22 is displayed. You can set attributes such as font, background, position, and text.
The preceding describes how to add controls to page files and set control properties. In this way, you can design the program interface. Table 2-1 and Table 2-2 lists the controls and attribute settings used in the Webform1.aspx and display. aspx files in this example.

Figure 2-22 style generator of the HTML Control

Table 2-1 controls contained in the Webform1.aspx file and their attributes

 

Table 2-2 controls contained in the display. aspx file and their attributes


The Webform1.aspx and postback. aspx interfaces are as follows: 2-23 and 2-24, respectively.

 

Figure 2-23 Webform1.aspx page

 

Figure 2-24 display. aspx


3) write the program code. ASP. NET program code is mainly used for event processing and database access. In this example, only event processing is performed without database access.
Double-click the BtnSubmit button control on the WebForm1.aspx interface. The code editing window is displayed. Enter the following program code:
Private Sub BtnSubmit_Click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles BtnSubmit. Click
Dim sex As String
If RBSex1.Checked Then 'If "male" is selected
Sex = RBSex1.Text
Else
If RBSex2.Checked then' If "female" is selected
Sex = RBSex2.Text
End If
End If
Response. Redirect ("display. aspx? Name = "& TxtName. Text &" & Age = "&_
TxtAge. Text & "& sex =" & sex) 'directs the process to display. aspx
End Sub
The process header in the program:
Private Sub BtnSubmit_Click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles BtnSubmit. Click
And process end sign:
End Sub
Is automatically generated by VS. NET.
Compile the Page_Load event handler in the display. aspx file as follows:
Private Sub Page_Load (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles MyBase. Load
LblName. Text = Request ("Name ")
LblAge. Text = Request ("Age ")
LblSex. Text = Request ("Sex ")
End Sub
4) view the running result in the browser. VS. NET provides a built-in browser window. Right-click the blank area of the application interface on which you want to view the page, and the shortcut menu shown in 2-25 is displayed, select view in browser to view the page.

 

Figure 2-25 shortcut menu


Of course, you can also view the running result directly in the browser according to the method described above.
So far, all the work of designing and running an ASP. NET application in VS. NET has been completed.
Development of application projects often requires the help of development tools to improve production efficiency, while learning ASP. from the perspective of NET, you should use the method of writing programs directly in the text editor, focus on the program design itself, the example of this book will be given in this way.


BibliographyPrevious sectionNext section

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.