ASP.NET 编写简单的Web应用程序

ASP.NET 编写简单Web应用程序

 

目标:编写Web应用程序,使用Web控件,进行状态管理,身份验证机数据库读写数据.

 

   ASP.NET可以创建能在任意浏览器上显示的Web应用程序. Web应用程序的底层技术是HTTP和HTML. ASP.NET的服务端控件抽象出了HTML代码,并模仿了Windows控件的行为.

   Web应用程序会让Web服务器给客户机发送HTML代码,这些代码会显示在浏览器中,浏览器将解释这些HTML代码,向用户显示文本框、按钮、列表等.

   当浏览器上输入URL字符串时,会把HTTP请求发送给Web服务器,包含请求的文件名和客户机信息;Web服务器会返回一个HTTP响应给浏览器解释后显示.

   服务器系统需要ASP.NET运行库,用Internet Information Service(IIS)配置. 在开发过程中,可选择使用VS自己ASP.NET Web Development Server来测试和调试Web应用程序.

 

ASP.NET可以使用TextBox,Label, ComboBox和Calendar等控件创建HTML代码。

 

18.3 创建简单的 Web页面 Web Form.aspx

    

 

右击添加WebForm命名为Registration.aspx, 在设计视图中添加Table来存放控件。

选择菜单Table|Insert Table,设置为5行2列

 

 

Table中插入4个标签,3个文本框,1个下拉表和1个按钮,在属性中修改名称.

 

项目属性中 Start Action设置为 Current Page .

 

运行测试

 

运行时会自动启动ASP.NET Development Server

服务器端代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Registration.aspx.cs" Inherits="EventRegistrationWeb.Registration" %>

 

AutoEventWireup="true"

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">   //页面发送给客户端时,从<head>标记中删除了runat="server"特性

    <title></title>

    <style type="text/css">

       .auto-style1 {width: 100%;  }

        .auto-style2 { width: 227px;  }

    </style>

</head>

<body>

    <form id="form1" runat="server">  //form1可用于调用HtmlForm类的方法和属性.

<div>

    <table class="auto-style1">

            <tr>

                <td class="auto-style2">  <asp:Label ID="LabelEvent" runat="server" Text="Event:"></asp:Label>     </td>

                <td>

                    <asp:DropDownList ID="DropDownListEvents" runat="server">

                        <asp:ListItem>INtroduce to ASP&gt;NET</asp:ListItem>

                        <asp:ListItem>Introduction to Windows Azure</asp:ListItem>

                        <asp:ListItem>Takeoff to .NET4.0</asp:ListItem>

                    </asp:DropDownList>

                </td>

            </tr>

            <tr>

                <td class="auto-style2"> <asp:Label ID="LabelFirstname" runat="server" Text="Firstname:"></asp:Label></td>

                <td> <asp:TextBox ID="TextFirstname" runat="server" Width="245px"></asp:TextBox>  </td>

            </tr>

            <tr>

                <td class="auto-style2"> <asp:Label ID="LabelLastname" runat="server" Text="Lastname:"></asp:Label>  </td>

                <td> <asp:TextBox ID="TextLastname" runat="server" Width="245px"></asp:TextBox> </td>

            </tr>

            <tr>

                <td class="auto-style2"><asp:Label ID="LabelEmail" runat="server" Text="Email:"></asp:Label> </td>

                <td> <asp:TextBox ID="TextEmail" runat="server" Width="245px"></asp:TextBox></td>

            </tr>

            <tr>

                <td class="auto-style2">&nbsp;</td> <td>  <asp:Button ID="ButtonSubmit" runat="server" Text="Submit" Width="179px" /> </td>

            </tr>

        </table>

    </div>

    </form>

</body>

</html>

 

<asp:开头的元素是服务器端的ASP.NET控件,与System.Web.UI.WebControls名称空间中的.NET类相关,也称为Web服务器控件。 ASP.NET的UI控件有Web服务器控件和HTML控件,HTML在System.Web.UI.HtmlControls名称空间中如果不需要在服务器端代码中给控件编程,就可以只使用HTML控件,而不添加runat=”server”特性.

转载于:https://www.cnblogs.com/sevenyang/p/9875706.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值