您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
asp.net高级教程(五)-实战篇(中)
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 12:37:04
asp.net高级教程(五)---实战篇(结合论坛用户操作谈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>&nbsp;

    <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>
        <!--------------用户密码结束-------------------------------------------------------->
        
 &

[1] [2] [3] [4] 下一页


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |