aspx代码
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="two.aspx.cs" Inherits="two" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
.auto-style1 { width:100%; }
.auto-style2 { height:21px; }
.auto-style3 { height:21px;width:93px; }
.auto-style4 { width:93px; }
.auto-style5 { height:21px;width:135px; }
.auto-style6 { width:135px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style3" style="text-align: right">用户名:</td>
<td class="auto-style5">
<asp:TextBox ID="txtName" runat="server" Width="120px"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:RequiredFieldValidator ID="vfvName" runat="server" ControlToValidate="txtName" Display="Dynamic" ErrorMessage="请输入用户名!" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style3" style="text-align: right">密码:</td>
<td class="auto-style5">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="120px"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="txtPassword" Display="Dynamic" ErrorMessage="请输入密码!" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style4" style="text-align: right">性别:</td>
<td class="auto-style6">
<asp:RadioButtonList ID="sex" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style4" style="text-align: right">电话号码:</td>
<td class="auto-style6">
<asp:TextBox ID="txtTelephone" runat="server" Width="120px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvTelephone" runat="server" ControlToValidate="txtTelephone" Display="Dynamic" ErrorMessage="请输入电话号码!" SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revTelephone" runat="server" ControlToValidate="txtTelephone" Display="Dynamic" ErrorMessage="电话号码格式应为1xxxxxxxxxx!" ValidationExpression="\d{3}-\d{8}" SetFocusOnError="True"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="text-align:right">
<asp:Button ID="BtnSubmit" runat="server" Text="注册" OnClick="BtnSubmit_Click" />
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="two.aspx.cs" Inherits="two" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<style type="text/css">
.auto-style1 { width:100%; }
.auto-style2 { height:21px; }
.auto-style3 { height:21px;width:93px; }
.auto-style4 { width:93px; }
.auto-style5 { height:21px;width:135px; }
.auto-style6 { width:135px; }
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style3" style="text-align: right">用户名:</td>
<td class="auto-style5">
<asp:TextBox ID="txtName" runat="server" Width="120px"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:RequiredFieldValidator ID="vfvName" runat="server" ControlToValidate="txtName" Display="Dynamic" ErrorMessage="请输入用户名!" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style3" style="text-align: right">密码:</td>
<td class="auto-style5">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password" Width="120px"></asp:TextBox>
</td>
<td class="auto-style2">
<asp:RequiredFieldValidator ID="rfvPassword" runat="server" ControlToValidate="txtPassword" Display="Dynamic" ErrorMessage="请输入密码!" SetFocusOnError="True"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td class="auto-style4" style="text-align: right">性别:</td>
<td class="auto-style6">
<asp:RadioButtonList ID="sex" runat="server" RepeatDirection="Horizontal">
<asp:ListItem>男</asp:ListItem>
<asp:ListItem>女</asp:ListItem>
</asp:RadioButtonList>
</td>
</tr>
<tr>
<td class="auto-style4" style="text-align: right">电话号码:</td>
<td class="auto-style6">
<asp:TextBox ID="txtTelephone" runat="server" Width="120px"></asp:TextBox>
</td>
<td>
<asp:RequiredFieldValidator ID="rfvTelephone" runat="server" ControlToValidate="txtTelephone" Display="Dynamic" ErrorMessage="请输入电话号码!" SetFocusOnError="True"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revTelephone" runat="server" ControlToValidate="txtTelephone" Display="Dynamic" ErrorMessage="电话号码格式应为1xxxxxxxxxx!" ValidationExpression="\d{3}-\d{8}" SetFocusOnError="True"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="text-align:right">
<asp:Button ID="BtnSubmit" runat="server" Text="注册" OnClick="BtnSubmit_Click" />
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
cs代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class two : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
lblMsg.Text = "";
if(Page.IsValid)
{
lblMsg.Text = "验证通过!";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class two : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void BtnSubmit_Click(object sender, EventArgs e)
{
lblMsg.Text = "";
if(Page.IsValid)
{
lblMsg.Text = "验证通过!";
}
}
}