客户端
1 <%@ Page Title="" Language="C#" MasterPageFile="~/Master/MainMaster.Master" AutoEventWireup="true" CodeBehind="Register.aspx.cs" Inherits="BookShop.Web.Member.Register" %> 2 <asp:Content ID="Content1" ContentPlaceHolderID="Header" runat="server"> 3 <style type="text/css"> 4 .auto-style1 { 5 height: 35px; 6 } 7 .regnow { 8 width:300px; 9 margin-left:30px; 10 height:40px; 11 background:#db2f2f; 12 border:none; 13 color: #FFF; 14 font-size: 15px; 15 font-weight: 700; 16 cursor:pointer; 17 } 18 </style> 19 <script type="text/javascript"> 20 $(function () { 21 $("#userMail").blur(function () { 22 validateEmail(); 23 }); 24 $("#validateCode").blur(function () { 25 validateUserCode(); 26 }); 27 $("#btnRegister").click(function () {//注册 28 if ($("#userMail").val() == "") { $("#msg").text("邮箱不能为空!!"); return false } 29 if ($("#validateCode").val() == "") { $("#validateCodeMsg").text("验证码不能为空!!"); return false } 30 var par = $("#aspnetForm").serializeArray(); 31 $.post("/ashx/UserRegister.ashx", par, function (data) { 32 $("#validateCodeMsg").text(data); 33 }); 34 }); 35 }); 36 //验证邮箱 37 function validateEmail() { 38 var val = $("#userMail").val(); 39 if (val != "") { 40 var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; 41 if (reg.test(val)) { 42 $("#msg").css("display", "none"); 43 $.post("/ashx/ValidateReg.ashx", { "action": "mail", "userMail": val }, function (data) { 44 $("#msg").css("display", "block"); 45 $("#msg").text(data); 46 }); 47 } else { 48 $("#msg").text("邮箱格式错误!!"); 49 50 } 51 52 } else { 53 $("#msg").text("邮箱不能为空!!"); 54 } 55 } 56 //验证校验码 57 function validateUserCode() { 58 var code = $("#validateCode").val(); 59 if (code != "") { 60 var reg = /^[0-9]*$/; 61 if (reg.test(code)) { 62 $.post("/ashx/ValidateReg.ashx", { "action": "code", "validateCode": code }, function (data) { 63 $("#validateCodeMsg").text(data); 64 }); 65 } 66 else { 67 $("#validateCodeMsg").text("验证码格式错!!"); 68 } 69 70 } else { 71 $("#validateCodeMsg").text("验证码不能为空!!"); 72 } 73 } 74 75 76 </script> 77 78 79 </asp:Content> 80 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> 81 82 <div style="font-size:small"> 83 <table width="80%" height="22" border="0" align="center" cellpadding="0" cellspacing="0"> 84 <tr> 85 <td style="width: 10px"><img src="../Images/az-tan-top-left-round-corner.gif" width="10" height="28" /></td> 86 <td bgcolor="#DDDDCC"><span class="STYLE1">注册新用户</span></td> 87 <td width="10"><img src="../Images/az-tan-top-right-round-corner.gif" width="10" height="28" /></td> 88 </tr> 89 </table> 90 91 92 <table width="80%" height="22" border="0" align="center" cellpadding="0" cellspacing="0"> 93 <tr> 94 <td width="2" bgcolor="#DDDDCC"> </td> 95 <td><div align="center"> 96 <table height="61" cellpadding="0" cellspacing="0" style="height: 332px"> 97 <tr> 98 <td height="33" colspan="6"><p class="STYLE2" style="text-align: center">注册新帐户方便又容易</p></td> 99 </tr> 100 <tr> 101 <td width="24%" align="center" valign="top" style="height: 26px">用户名</td> 102 <td valign="top" width="37%" align="left" style="height: 26px"> 103 <input type="text" name="txtName" /></td> 104 </tr> 105 <tr> 106 <td width="24%" height="26" align="center" valign="top">真实姓名:</td> 107 <td valign="top" width="37%" align="left"> 108 <input type="text" name="txtRealName" /></td> 109 </tr> 110 <tr> 111 <td width="24%" height="26" align="center" valign="top">密码:</td> 112 <td valign="top" width="37%" align="left"> 113 <input type="password" name="txtPwd" /></td> 114 </tr> 115 <tr> 116 <td width="24%" height="26" align="center" valign="top">确认密码:</td> 117 <td valign="top" width="37%" align="left"> 118 <input type="password" name="txtConfirmPwd" /></td> 119 </tr> 120 <tr> 121 <td width="24%" height="26" align="center" valign="top">Email:</td> 122 <td valign="top" width="37%" align="left"> 123 <input type="text" name="txtEmail" id="userMail" /><span id="msg" style="font-size:14px;color:red"></span></td> 124 </tr> 125 <tr> 126 <td width="24%" height="26" align="center" valign="top">地址:</td> 127 <td valign="top" width="37%" align="left"> 128 <input type="text" name="txtAddress" /></td> 129 </tr> 130 <tr> 131 <td width="24%" height="26" align="center" valign="top">手机:</td> 132 <td valign="top" width="37%" align="left"> 133 <input type="text" name="txtPhone" /></td> 134 </tr> 135 <tr> 136 <td width="24%" align="center" valign="top" class="auto-style1"> 137 验证码:</td> 138 <td valign="top" width="37%" align="left" class="auto-style1"> 139 <input type="text" name="txtCode" id="validateCode" /><span id="validateCodeMsg" style="font-size:14px;color:red"></span><img src="/ashx/ValidateCode.ashx" /></td> 140 </tr> 141 <tr> 142 <td colspan="2" align="center"><input type="button" value="注册" class="regnow" id="btnRegister"/></td> 143 </tr> 144 <tr> 145 <td colspan="2" align="center"> </td> 146 </tr> 147 </table> 148 <div class="STYLE5">---------------------------------------------------------</div> 149 </div> 150 </td> 151 <td width="2" bgcolor="#DDDDCC"> </td> 152 </tr> 153 </table> 154 155 <table width="80%" height="3" border="0" align="center" cellpadding="0" cellspacing="0"> 156 <tr> 157 <td height="3" bgcolor="#DDDDCC"><img src="../Images/touming.gif" width="27" height="9" /></td> 158 </tr> 159 </table> 160 </div> 161 162 </asp:Content>
服务器端
1 public partial class Register : System.Web.UI.Page 2 { 3 protected void Page_Load(object sender, EventArgs e) 4 { 5 if (IsPostBack) 6 { 7 if (Common.WebCommon.CheckValidateCode(Request["txtCode"]))//完成验证码校验 8 { 9 AddUserInfo(); 10 } 11 } 12 } 13 #region 完成用户注册 14 protected void AddUserInfo() 15 { 16 Model.User userInfo = new Model.User(); 17 userInfo.Address = Request["txtAddress"]; 18 userInfo.LoginId=Request["txtName"]; 19 userInfo.LoginPwd=Request["txtPwd"]; 20 userInfo.Mail = Request["txtEmail"]; 21 userInfo.Name = Request["txtRealName"]; 22 userInfo.Phone=Request["txtPhone"]; 23 24 25 userInfo.UserState.Id =Convert.ToInt32(UserStateEnum.NormalState); 26 BLL.UserManager userManager = new BLL.UserManager(); 27 string msg=string.Empty; 28 if (userManager.Add(userInfo, out msg) > 0) 29 { 30 Session["userInfo"] = userInfo; 31 Response.Redirect("/Default.aspx"); 32 } 33 else 34 { 35 Response.Redirect("/ShowMsg.aspx?msg="+msg+"&txt=首页"+"&url=/Default.aspx"); 36 } 37 38 } 39 #endregion 40 41 #region 验证码校验 42 //protected bool CheckSession() 43 //{ 44 // //bool isSucess = false; 45 // //if (Session["vCode"] != null) 46 // //{ 47 // // string txtCode = Request["txtCode"]; 48 // // string sysCode = Session["vCode"].ToString(); 49 // // if (sysCode.Equals(txtCode, StringComparison.InvariantCultureIgnoreCase)) 50 // // { 51 // // isSucess = true; 52 // // Session["vCode"] = null; 53 // // } 54 55 // //} 56 // //return isSucess; 57 58 //} 59 #endregion 60 61 }