asp.net教程:项目实战讲解(二)
做好准备工作,现在就要动真格的了,先让我们看看用户注册的实现。前边已经讲过,asp.net可以实现业务逻辑和html代码分离,那么让我们来看看到底是如何实现的,下面这个文件是用户注册的页面部分,原型是根据我站点的风格制作的:
<%@Page language="c#" Codebehind="Register.cs" AutoEventWireup="false" Inherits="bbs.Register" %>
<%@Register Tagprefix="My" Namespace="bbs.uctrl"%>
<html><head>
<TITLE>新用户注册</TITLE>
<meta name=vs_targetSchema content="HTML 4.0">
<link rel="stylesheet" href="images/style.css">
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#"></head>
<script language=javascript>
function OnPreview()
{
divPreview.innerHTML = Form1.txtSignature.value ;
}
</script>
<body>
<form method="post" runat="server" ID=Form1>
<My:MyHead id="myHead1" runat="server"></MY:MYHEAD>
<!----------------------外面表格形成边框-------------------------------------->
<table width='722' border='0' cellspacing=0
cellpadding='0' align='center'>
<TBODY>
<tr>
<!-------------------左边竖线---------------------------------------------->
<td bgcolor='#0097c0' width='1'>
<img src='images/Shim.gif' width=1>
</td>
<td width=720 align=middle><br><br><br>
<!-------------------左边竖线---------------------------------------------->
<!--------------新用户注册开始---------------------------------------------->
<table width=600 align=center border=0 cellpadding=4 cellspacing=1
id="tblRegister" class=cn bgcolor=#000000 runat=server>
<TBODY>
<tr bgcolor=#ffffff>
<td colspan=3>
<p align=center>新用户注册</p>
</td>
</tr>
<!--------------用户名开始-------------------------------------------------------->
<tr bgcolor=#ffffff>
<td width=60>
用户名
</td>
<td width=300>
<asp:TextBox id="txtUserName" maxlength=20 columns=20 runat="server"></asp:TextBox>
<font color=red>*</font>
</td>
<td width=240>
用户笔名,4-20字符
<asp:requiredfieldvalidator id="reqUserName" display=Dynamic
controltovalidate="txtUserName" runat=Server>
不能为空!
</asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id="regUserName" display=Dynamic
controltovalidate="txtUserName" runat=Server validationexpression="[^']{4,20}">
用户名非法!
</asp:regularexpressionvalidator>
<asp:customvalidator id="cusUserName" controltovalidate="txtUserName"
onservervalidate="ValidUser" display=Dynamic runat=Server>
该用户已存在。
</asp:customvalidator>
</td>
</tr>
<!--------------用户名结束-------------------------------------------------------->
<!--------------用户密码开始-------------------------------------------------------->
<tr bgcolor=#ffffff>
<td width=60>
密码
</td>
<td width=300>
<asp:TextBox id="txtPassword" maxlength=10 columns=10
textmode=Password runat=server></asp:TextBox>
<font color=red>*</font>
</td>
<td width=240>
用户密码,4-10字符
<asp:requiredfieldvalidator id=Requiredfieldvalidator1 display=Dynamic
controltovalidate="txtPassword" runat=Server>
不能为空!
</asp:requiredfieldvalidator>
<asp:regularexpressionvalidator id=Regularexpressionvalidator1 display=Dynamic
controltovalidate="txtPassword" runat=Server validationexpression="[^']{4,10}">
密码非法!
</asp:regularexpressionvalidator>
</td>
</tr>
<!--------------用户密码结束-------------------------------------------------------->
<!--------------验证密码开始-------------------------------------------------------->
<tr bgcolor=#ffffff>
<td width=60>
验证密码
</td>
<td width=300>
<asp:TextBox id=txtPassword1 maxlength=10 columns=10
textmode=Password runat=server></asp:TextBox>
<font color=red>*</font>
</td>
<td width=240>
再次输入密码。
<asp:comparevalidator id="comPassword" display=Dynamic
controltocompare="txtPassword" controltovalidate="txtPassword1" runat=Server>
两次录入的密码不同!
</asp:comparevalidator>
</td>
</tr>
<!--------------验证密码结束-------------------------------------------------------->
<!--------------email开始-------------------------------------------------------->
<tr bgcolor=#ffffff>
<td width=60>
Email
</td>
<td width=300>
<asp:TextBox id="txtEmail" maxlength=100 columns=30 runat=server></asp:TextBox>
</td>
<td width=240>
您的电子邮件地址,您可以不填,但请不要胡填。
<asp:regularexpressionvalidator id="regEmail" display=Dynamic
controltovalidate="txtEmail" validationexpression="[^']*" runat=Server>
非法字符
</asp:regularexpressionvalidator>
</td>
</tr>
<!--------------email结束-------------------------------------------------------->
<!--------------个人主页开始-------------------------------------------------------->
<tr bgcolor=#ffffff>
<td width=60>
个人主页
</td>
<td width=300>
<asp:TextBox id="txtHomepage" maxlength=150 columns=30 runat=server></asp:TextBox>
</td>
<td width=240>
您的主页,您可以不填,但请不要胡填。
<asp:regularexpressionvalidator id="regHomepage" display=Dynamic
controltovalidate="txtHomepage" validationexpression="[^']*" runat=Server>
非法字符。
</asp:regularexpressionvalidator>
</td>
</tr>
<!--------------个人主页结束-------------------------------------------------------->
<!--------------签名开始-------------------------------------------------------->
<tr bgcolor=#ffffff>
<td width=60>
签名
</td>
<td width=300>
<asp:TextBox id="txtSignature" maxlength=150 columns=30 rows=6 textmode=MultiLine runat=server></asp:TextBox>
</td>
<td width=240 valign=top>
<div id="divPreview">
你可以制作自己的签名,不超过255个字符,不能用script。<br><br>
</div><br>
<input type=button id="btnPreview" value="预览" onclick="OnPreview()"><br>
<asp:regularexpressionvalidator id=Regularexpressionvalidator2 display=Dynamic
controltovalidate="txtSignature" validationexpression="[^']{0,255}" runat=Server>
使用非法字符或超过255个字符。
</asp:regularexpressionvalidator>
</td>
</tr>
<!--------------签名结束-------------------------------------------------------->
<tr bgcolor=#ffffff>
<td colspan=3 align=center>
<asp:button id="btnSubmit" text="确认" onclick="OnSubmit" runat=Server></asp:button>
</td>
</tr>
</table><br><br><br>
<!----------------------------------新用户注册结束---------------------->
<!-------------------右边竖线---------------------------------------------->
<td bgcolor='#0097c0' width='1'>
<img src='images/Shim.gif' width=1>
</td>
<!-------------------右边竖线---------------------------------------------->
</tr>
<!-------------------下边横线---------------------------------------------->
<tr>
<td colspan=3 height=1 bgcolor=#0097c0><img src='images/shim.gif'width=1 height=1></td>
</tr>
<!-------------------下边横线---------------------------------------------->
</table>
<My:bottom id="myBottom" runat="server"></My:bottom>
</form>
</BODY></HTML>
<!--------------------文件结束--------------------------------->
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |