webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="dynamicweb4_1.WebForm1" %>
<!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: 350px;
height: 200px;
border: 1px solid #000066;
}
.td-left {
font-size: small;
font-weight: bold;
vertical-align: middle;
text-align: right;
width: 150px;
}
.td-right {
font-size: small;
font-weight: bold;
vertical-align: middle;
text-align: left;
width: 200px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<center><h3>用户注册</h3></center>
<table align="center" cellpadding="0" cellspacing="0" class="auto-style1">
<tr>
<td class="td-left">
用户名:
</td>
<td class="td-right">
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="td-left">密码:</td>
<td class="td-right">
<asp:TextBox ID="txtPassword1" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td class="td-left">
再次输入密码:
</td>
<td class="td-right">
<asp:TextBox ID="txtPassword2" runat="server" TextMode="Password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnSubmit" runat="server" Text="注册" OnClick="btnSubmit_Click"/>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Label ID="lblTips" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace dynamicweb4_1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtName.Text))
{
lblTips.Text = "请输入用户名";
lblTips.ForeColor = System.Drawing.Color.Red;
txtName.Focus();
}
else if(string.IsNullOrEmpty(txtPassword1.Text) || string.IsNullOrEmpty(txtPassword2.Text))
{
lblTips.Text = "请输入密码";
lblTips.ForeColor = System.Drawing.Color.Red;
txtPassword2.Focus();
}
else if (txtPassword1.Text != txtPassword2.Text)
{
lblTips.Text = "两次输入密码不一致";
lblTips.ForeColor = System.Drawing.Color.Red;
txtPassword1.Focus();
}
else
{
lblTips.Text = "注册成功";
}
}
}
}