一个简单的WEB应用 VS2005

  1. 下载Visual Studio 2005 Web Application Projects 插件.
  2. 启动Visual Studio 2005.
  3. File]-->[New]-->[Project].
  4. 选择 [Visual Basic] 的Project Type
  5. 选择[ ASP.NET Web Application]的Template

    Visual Studio 会创建一个单页的WEB应用程序,并且设计器已经建立好了初步的代码框架

  6. 点击底部的[Design]即可切换到 WYSIWYG (所见即所得)视图.
  7. 点击设计界面,入如下Enter your name: .
  8. 从工具箱拖一个Textbox控件到设计界面, 放在刚刚的 Enter your name: 后面.
  9. 从工具箱拖一个Button 控件到设计界面.放在Textbox的下一行
  10. 从工具箱拖一个Label 控件到设计界面, 放在Button的下一行.

      页面布局
    1. 选中页面上的内容,按 DELETE 清除.
    2. Layout菜单中选择 Insert Table.
    3. Rows上键入 2.
    4. Columns上键入 2.
    5. 单击OK.

    6.  可以在表格单元中加入任意的控件,会起到很好的对齐作用,因此,表格是控制WEB页面布局很重要的机制 !

    事件驱动

    1. 双击Button控件以编辑 Click事件
    2. 键入代码:Label1.Text = "Welcome " & TextBox1.Text
    3. 按F5 运行.
    4. 在 User Name 文本框中输入名字.
    5. 单击Button控件

       

    使用SESSION

    1. In Visual Studio 2005, in the Solution Explorer, right-click Default.aspx, and then click View Code.
    2. On a line after Inherits System.Web.UI.Page, enter the following code.
      Public previousUser As String
      
    3. Modify the code for the Button1_Click event handler as follows.
      Label1.Text = "You were " & previousUser & ", and now you're " & TextBox1.Text
      previousUser = TextBox1.Text
      
    4. Press F5 to run the application.
    5. Enter Fred and click the button.
    6. Enter Jim and click the button.

      Notice that the previousUser value is never showing up. It is always saying You were , and now you're Jim. What is going on?

    7. Modify the code for the Button1_Click event handler as follows.
      Label1.Text = "You were " & Session("previousUser") & ", and now you're " & TextBox1.Text
      Session("previousUser") = TextBox1.Text
      
    8. Press F5 to run the application.
    9. Enter Fred and click the button.
    10. Enter Jim and click the button.

      Now you are getting the correct behavior (see Figure 5). By using Session variables, the site is able to remember information across user interactions.

       

    使用数据库

     you need to download and install SQL Express and the sample Northwind database.

    1. In the Solution Explorer, on the Project menu, click Add New Item.
    2. For Template, select WebForm, and then click Add.
    3. Click the Design tab at the bottom of the code editor window.
    4. From the Data section of the Toolbox, drag a GridView control onto the designer.
    5. From the GridView Tasks smart tag, click Choose Data Source, and then click <New data source>.
    6. In the Choose a Data Source Type dialog box, select Database, and then click OK.
    7. Click New Connection.
    8. For Server Name, enter localhost if you have SQL Server installed. If you have SQL Express installed, enter ./sqlexpress.
    9. For Select or enter a database, enter Northwind.
    10. Click Test Connection to ensure that you can connect to the database.
    11. Click OK.
    12. Click Next.
    13. In the Save the Connection String dialog box, click Next.
    14. In the Name drop-down list, click Orders.
    15. For Columns, select *.
    16. Click Next.
    17. Click Test Query to ensure that communication with the database functions as expected.
    18. Click Finish.  
    19. Right-click the GridView control, and then click Auto Format.
    20. Choose one of the formats, such as Professional.
    21. Right-click the GridView control, and then click Properties.
    22. In the Properties Panel, set the AllowPaging property to True.
    23. Set the AllowSorting property to True.
    24. Press F5 to run the Web application.
    25. The application should appear as shown in Figure 6.

         

      Click here for larger image

      You can click column headings to sort on that column. You can click on the page numbers at the bottom to page through the results.

    ASP.NET 2.0 的其他重要特性

    Master Pages

    With Desktop applications, it is easy to simply put the appropriate menus and toolbars on individual forms. With Web sites, however, the navigation is typically more global. A single navigation bar is often displayed on all pages of the site. ASP.NET provides the capability to do this through Master pages. You simply add a Master page as an item to your solution. You use tables on the Master page to control where the header, navigation bar, footer, main page content, and so on should go. Then, you have a particular content page reference the Master page. The page content will appear inside the Master page, in the content area.

    Figure

  11.  

    Authentication and Authorization

    It is very common to have a site, or portion of a site, that requires a user name and password in order to gain access. ASP.NET 2.0 provides extensive support for this scenario. First, ASP.NET gives you a site administration tool that includes a Wizard that will walk you through configuring sections of your site for membership

  12. Security Setup Wizard

     

    小结

    Web development is different from Desktop development. However, the ASP.NET programming model provides a number of striking similarities. When building Web sites, you simply wire up event handlers for controls, just like you would do with desktop applications. Managing state is different, because pages are created and destroyed on each request, but ASP.NET does provide the Session variable to let you persist information in memory on the server. ASP.NET also includes simple-to-use yet powerful controls for common scenarios, such as building data-centric Web sites. Finally, ASP.NET includes full wizards to walk you through site configuration for complex tasks, such as enabling authentication and authorization.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值