Creating Web Applications with ASP.NET
Số trang: 20
Loại file: pdf
Dung lượng: 59.38 KB
Lượt xem: 7
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tạo ứng dụng Web với ASP.NET ứng dụng A Web có sử dụng ASP.NET thường bao gồm một hoặc nhiều trang Web ASP.NET hình thức, các tập tin mã, và các file cấu hình.
Nội dung trích xuất từ tài liệu:
Creating Web Applications with ASP.NET Creating Web Applications with ASP.NETA Web application that uses ASP.NET typically consists of one or more ASP.NET pagesor Web forms, code files, and configuration files.A Web form is held in an .aspx file, which is essentially an HTML file with someMicrosoft .NET–specific tags. An .aspx file defines the layout and appearance of a page.Each .aspx file often has an associated code file containing the application logic for thecomponents in the .aspx file, such as event handlers and utility methods. A tag, ordirective, at the start of each .aspx file specifies the name and location of thecorresponding code file. ASP.NET also supports application-level events, which aredefined in Global.asax files.Each Web application can also have a configuration file called Web.config. This file,which is in XML format, contains information regarding security, cache management,page compilation, and so on.Building an ASP.NET ApplicationIn the following exercise, you will build a simple ASP.NET application that uses Servercontrols to gather input from the user about the details of the employees of a fictitioussoftware company. The application will show you the structure of a typical Webapplication.NOTEYou do not need to have IIS running on your computer in order to develop Webapplications. Visual Studio 2005 includes its own Development Web server. When youbuild and run a Web application, by default Visual Studio 2005 will run the applicationusing this server. However, you should still use IIS for hosting production Webapplications after you have finished developing and testing them.Create the Web application 1. Start Microsoft Visual Studio 2005, if it is not already running. 2. On the File menu, point to New and then click Web Site. The New Web Site dialog box appears. 3. Click the ASP.NET Web Site template. Select File System in the Location drop- down list box, and type C:\Documents and Settings\YourName\My Documents\Microsoft Press\Visual CSharp Step by Step\Chapter 25\HonestJohn where YourName is your Windows login name. Set the Language to Visual C#, and then click OK. NOTE Setting the Location to FileSystem uses the Development Web server provided with Visual Studio 2005. You can use IIS by setting the Location to HTTP and specifying the URL of the Web Site you want to create rather than a file name. An application is created consisting of a Web Folder called App_Data, and a Web form called Default.aspx. The HTML code for the default page appears in the Source View window. 4. In the Solution Explorer select the Default.aspx file. In the Properties window, change the File Name property of Default.aspx to EmployeeForm.aspx. 5. Click the Design button at the bottom of the form to display the Design View of the form. The Design View window is currently empty. In the Design View window, you can drag controls onto the Web form from the Toolbox, and Visual Studio 2005 will generate the appropriate HTML for you. This is the HTML that you see when you view the form in the Source View window. You can also edit the HTML directly if you want.In the next exercise, you will define a style to be used by the form and add controls to theform to make it functional. Using a style enables you to ensure that all controls on theform share a common look and feel (such as color and font), as well as setting items suchas a background image of the form.Lay out the Web form 1. Click the form in the Design View window. In the Properties window, change the Title property of the DOCUMENT object to Employee Information. The value you specify for the Title property appears in the title bar of the Web Browser when you run the Web application. 2. Select the Style property and click the ellipses button. The Style Builder dialog box opens. This dialog box allows you to create a style for the form. (A style specifies the default font, color, layout, and other attributes for the Web form and its controls.)3. In the Font Name section, verify that the Family option is selected, and then click the ellipses button on the right side. In the Font Picker dialog box that opens, select Arial in the Installed Fonts list, and then click the >> button to add it to the Selected Fonts list. Click OK to return to the Style Builder dialog box.4. In the Color drop-down list, select Blue.5. In the left pane of the dialog box, click Background. The Background page is displayed. Select the Transparent check box.6. Using Windows Explorer, copy the file \Microsoft Press\Visual CSharp Step By Step\Chapter 25\computer.bmp in your My Documents folder to the \Microsoft Press\Visual CSharp Step By Step\Chapter 25\HonestJohn folder.7. Return to the Style Builder dialog box in the Visual Studio 2005 programming environment. In the Image text box, type computer.bmp. Click OK. The Web form will contain a background image of a computer.8. Open the Toolbox and ensure that the Standard category is expanded. The Toolbox contains controls that you can drop onto ASP.NET forms. These controls are similar, in many cases, to the controls you have been using to build Windows forms. The difference is that these controls have been designed to operate in an HTML environment, and they are rendered using HTML at run time.9. From the Toolbox, drag and drop four Label controls and three TextBox controls onto the Web form. Notice how the controls pick up the font and color specified by the Web forms style. NOTE The controls will be automatically positioned using a left-to-right flow layout in the Design View window. Do not worry about their location just yet as you will move them after setting their properties. ...
Nội dung trích xuất từ tài liệu:
Creating Web Applications with ASP.NET Creating Web Applications with ASP.NETA Web application that uses ASP.NET typically consists of one or more ASP.NET pagesor Web forms, code files, and configuration files.A Web form is held in an .aspx file, which is essentially an HTML file with someMicrosoft .NET–specific tags. An .aspx file defines the layout and appearance of a page.Each .aspx file often has an associated code file containing the application logic for thecomponents in the .aspx file, such as event handlers and utility methods. A tag, ordirective, at the start of each .aspx file specifies the name and location of thecorresponding code file. ASP.NET also supports application-level events, which aredefined in Global.asax files.Each Web application can also have a configuration file called Web.config. This file,which is in XML format, contains information regarding security, cache management,page compilation, and so on.Building an ASP.NET ApplicationIn the following exercise, you will build a simple ASP.NET application that uses Servercontrols to gather input from the user about the details of the employees of a fictitioussoftware company. The application will show you the structure of a typical Webapplication.NOTEYou do not need to have IIS running on your computer in order to develop Webapplications. Visual Studio 2005 includes its own Development Web server. When youbuild and run a Web application, by default Visual Studio 2005 will run the applicationusing this server. However, you should still use IIS for hosting production Webapplications after you have finished developing and testing them.Create the Web application 1. Start Microsoft Visual Studio 2005, if it is not already running. 2. On the File menu, point to New and then click Web Site. The New Web Site dialog box appears. 3. Click the ASP.NET Web Site template. Select File System in the Location drop- down list box, and type C:\Documents and Settings\YourName\My Documents\Microsoft Press\Visual CSharp Step by Step\Chapter 25\HonestJohn where YourName is your Windows login name. Set the Language to Visual C#, and then click OK. NOTE Setting the Location to FileSystem uses the Development Web server provided with Visual Studio 2005. You can use IIS by setting the Location to HTTP and specifying the URL of the Web Site you want to create rather than a file name. An application is created consisting of a Web Folder called App_Data, and a Web form called Default.aspx. The HTML code for the default page appears in the Source View window. 4. In the Solution Explorer select the Default.aspx file. In the Properties window, change the File Name property of Default.aspx to EmployeeForm.aspx. 5. Click the Design button at the bottom of the form to display the Design View of the form. The Design View window is currently empty. In the Design View window, you can drag controls onto the Web form from the Toolbox, and Visual Studio 2005 will generate the appropriate HTML for you. This is the HTML that you see when you view the form in the Source View window. You can also edit the HTML directly if you want.In the next exercise, you will define a style to be used by the form and add controls to theform to make it functional. Using a style enables you to ensure that all controls on theform share a common look and feel (such as color and font), as well as setting items suchas a background image of the form.Lay out the Web form 1. Click the form in the Design View window. In the Properties window, change the Title property of the DOCUMENT object to Employee Information. The value you specify for the Title property appears in the title bar of the Web Browser when you run the Web application. 2. Select the Style property and click the ellipses button. The Style Builder dialog box opens. This dialog box allows you to create a style for the form. (A style specifies the default font, color, layout, and other attributes for the Web form and its controls.)3. In the Font Name section, verify that the Family option is selected, and then click the ellipses button on the right side. In the Font Picker dialog box that opens, select Arial in the Installed Fonts list, and then click the >> button to add it to the Selected Fonts list. Click OK to return to the Style Builder dialog box.4. In the Color drop-down list, select Blue.5. In the left pane of the dialog box, click Background. The Background page is displayed. Select the Transparent check box.6. Using Windows Explorer, copy the file \Microsoft Press\Visual CSharp Step By Step\Chapter 25\computer.bmp in your My Documents folder to the \Microsoft Press\Visual CSharp Step By Step\Chapter 25\HonestJohn folder.7. Return to the Style Builder dialog box in the Visual Studio 2005 programming environment. In the Image text box, type computer.bmp. Click OK. The Web form will contain a background image of a computer.8. Open the Toolbox and ensure that the Standard category is expanded. The Toolbox contains controls that you can drop onto ASP.NET forms. These controls are similar, in many cases, to the controls you have been using to build Windows forms. The difference is that these controls have been designed to operate in an HTML environment, and they are rendered using HTML at run time.9. From the Toolbox, drag and drop four Label controls and three TextBox controls onto the Web form. Notice how the controls pick up the font and color specified by the Web forms style. NOTE The controls will be automatically positioned using a left-to-right flow layout in the Design View window. Do not worry about their location just yet as you will move them after setting their properties. ...
Tài liệu liên quan:
-
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 282 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 279 0 0 -
Bài thuyết trình Ngôn ngữ lập trình: Hệ điều hành Window Mobile
30 trang 274 0 0 -
Giáo trình Lập trình cơ bản với C++: Phần 1
77 trang 235 0 0 -
Bài giảng Một số hướng nghiên cứu và ứng dụng - Lê Thanh Hương
13 trang 231 0 0 -
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 223 0 0 -
Giáo án Tin học lớp 11 (Trọn bộ cả năm)
125 trang 219 1 0 -
Bài tập lập trình Windows dùng C# - Bài thực hành
13 trang 194 0 0 -
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 176 0 0 -
Giáo trình Lập trình C căn bản: Phần 1
64 trang 170 0 0