Danh mục

Creating a Simple ASP.NET Web Application Using VS .NET

Số trang: 8      Loại file: pdf      Dung lượng: 54.72 KB      Lượt xem: 12      Lượt tải: 0    
tailieu_vip

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Creating a Simple ASP.NET Web Application Using VS .NET In this section, youll see how to create a simple ASP.NET Web application that contains a text box and a button using VS .NET.
Nội dung trích xuất từ tài liệu:
Creating a Simple ASP.NET Web Application Using VS .NETCreating a Simple ASP.NET Web Application Using VS .NETIn this section, youll see how to create a simple ASP.NET Web application that containsa text box and a button using VS .NET. When you press the button, a string of text willappear in your text box. Youll learn how to deploy this application to Microsofts InternetInformation Server (IIS). Youll also see how to run the example Web application fromInternet Explorer.Note IIS is software that allows you to run ASP.NET Web applications and display HTML pages. To deploy the ASP.NET applications shown in this chapter, youll need access to a computer that runs IIS, along with the FrontPage Server Extensions. These extensions allow you to deploy an ASP.NET Web application from Visual Studio .NET. You can find full information on installing IIS and the FrontPage Server Extensions in the Windows online help documentation; to access this documentation, select Start ➣ Help.Perform the following steps: 1. Start Visual Studio .NET (VS .NET) and select File ➣ New Project. Select Visual C# Projects from the Project Types area on the left of the New Project dialog box, and select ASP .NET Web Application from the Templates area on the right. Enter http://localhost/MyWeb-Application in the Location field, as shown in Figure 15.1. Figure 15.1: Creating an ASP.NET Web application in Visual Studio .NET Note The name localhost represents your local computer on which you are developing your Web application. If youre using IIS that is running on a computer other than your local computer, you should replace localhost with the name of the remote computer.2. Click the OK button to continue. VS .NET will create a new directory named MyWebApplication in the wwwroot directory; this is the directory where IIS stores published Web pages and applications. After you click the OK button, youll see the new application being sent to IIS. Once your application has been deployed to IIS, VS .NET will display a blank Web form. You can think of the Web form as the canvas on which you can place controls, such as text boxes and buttons. When you later run your form, youll see that the page displayed by the Web browser is laid out in a similar manner to your form.3. Add a TextBox control to your form. The default value for the ID property of your TextBox control is TextBox1. Note You use the ID property when referencing a Web control in C# code. Youll see an example of code that does this shortly.4. Set the TextMode property for TextBox1 to MultiLine; this allows the text to be displayed on more than one line. Next, add a Button control to your form. The default ID for your Button control is Button1. Set the Text property for Button1 to Press Me! Figure 15.2 shows the form with the TextBox and Button controls. Figure 15.2: Adding TextBox and Button controls to the form5. Next, youll add a line of code to the Button1_Click() method. This method is executed when Button1 is pressed in your running form. The statement youll add to Button1_Click() will set the Text property of TextBox1 to a string. This string will contain a line from Shakespeares Romeo and Juliet. To add the code, double- click Button1 and enter the following code in the Button1_Click() method:6. TextBox1.Text =7. But, soft! what light through yonder window breaks? + 8. It is the east, and Juliet is the sun. + 9. Arise, fair sun, and kill the envious moon, + 10. Who is already sick and pale with grief, + 11. That thou her maid art far more fair than she; 12. Note If youre a Shakespeare fan, youll recognize these lines from the magnificent balcony scene in which Romeo professes his true love for Juliet. 13. Youre now ready to run your form. Select Debug ➣ Start Without Debugging, or press Ctrl+F5 on the keyboard to run your form (see Figure 15.3). Figure 15.3: The running formNow that youve created and run the form, lets examine the code generated by VS .NET.There are two main parts to the code: • The WebForm1.aspx file, which contains HTML and ASP.NET code. • The WebForm1.aspx.cs file, which contains C# code that supports the Web form. You can think of this C# code as running behind the form, and for this reason the WebForm1.aspx.cs file is known as the code-behind file.Note The extension .aspx identifies ASP.NET files.Youll examine the details of the WebForm1.aspx and WebForm1.aspx.cs files in thefollowing sections.The WebForm1.aspx FileYou can view the HTML containing the ASP.NET tags for your form by clicking theHTML link at the bottom of the form designer. Click the HTML link to view the code for ...

Tài liệu được xem nhiều: