JS code function CheckName () {var Msg = document.getElementById ("D_username"); var chk = Checkn (); if (chk) {$.ajax ({URL : ' Registerok.aspx ', type: ' POST ', data: {lb: ' CheckName ', Username: $ ("#username"). Val ()}, DataType: ' HTML ', timeout:1 Error:function () {alert (' There is an unknown error, please contact qq:6434789. '); }, Success:function (data) {if (data = = "Sorry, the user name has been registered!) ") {msg.classname =" d_err "; msg.innerhtml = data; $ ("#hiddencheckname"). Val ("no"); if (data = = "Congratulations, this user name can be registered! ") {msg.classname =" D_OK "; msg.innerhtml = data; $ ("#hiddencheckname"). Val ("yes"); if (data = = "The user name cannot be Chinese! ") {msg.classname =" d_err "; msg.innerhtml = data; $ ("#hiddencheckname"). Val ("no"); } if (data = = "Please enter the user name!") ") {msg.classname =" d_err "; msg.innerhtml = data; $ ("#hiddencheckname"). Val ("no"); } } }); }} function Checkn () {var Msg = document.getElementById ("D_username"); var chk = true; if (Checkischinese (Document.getel Ementbyid ("username"). Value) {msg.classname = "d_err"; msg.innerhtml = "User name cannot be Chinese!" "; CHK = false;} if (document.getElementById ("username"). Value.length < 4) {msg.classname = "d_err"; msg.innerhtml = "User name cannot be less than 4 characters!" "; CHK = false; } return chk; } function Chk_reguser () {var chk = true//if (!checkname ()) {chk = false;}//jquery the variable assignment cannot be shared with the variable in JS, so success:funct Ion (data) {} any variables defined inside the JS code are not the same, so I find a more biased (informal) method, to add hidden input in the HTML and in JS set the $ ("#hiddencheckname"). Val (" No "); if (! Checkn ()) {chk = false;} if ($ ("#hiddencheckname"). val () = = "No") {chk = false;} This is the judgment on it if (!checkpwd ()) {chk = false;} These are almost identical to checkn () except that the elements inside the form are verified if (!CHECKPWD1 ()) {chk = false;} if (!checkquestion ()) {chk = false;} if (!CHECKANSW ER ()) {chk = false;} if (!checkxq ()) {chk = false;} if (!checkrealname ()) {chk = false;} if (!checktel ()) {chk = FA Lse if (!checkqqmsn ()) {chk = false;} if (!checkemail ()) {chk = false;} if (!checkaddress ()) {chk = false;} if (CHK) { $.ajax ({url: ' registerok.aspx ', type: ' POST ', data: {lb: ' Reguser ', Username: $ ("#username"). Val (), Password: $ ("#pwd"). Val (), Question: $ ("#question"). Val (), Answer: $ ("#answer"). Val (), Xqcode: $ ("#ctl00_CPH_Main_DDL_xq"). Val (), Realname: $ ("#realname"). Val (), Sex: $ ("input[@name =sex][@checked]"). Val (), Tel: $ ("#tel"). Val (), Qqmsn: $ ("# Qqmsn "). Val (), Email: $ (" #email "). Val (), Address: $ (" #address "). Val ()}, DataType: ' HTML ', timeout:1000, error:function () {alert (' There is an unknown error, please contact qq:6434789. '); }, Success:function (data) {if (data = = "Success") {alert ("registered successfully! "); Window.location.href = "/member/index.aspx"; } else {alert ("Registration failed because the user name could have been registered! "); } } }); return (true); } return (FALSE); }
HTML page
Just make a form like this
<input id= "username" type= "text" onblur= "CheckName ()"/> <div class=d_default id=d_username> Please enter more than 4 characters or numbers in English! </div> <input id= "BUTTON_OK" type= "button" onclick= "return Chk_reguser ();" />
RegisterOK.aspx.cs
Using System; Using System.Collections.Generic; Using System.Linq; Using System.Web; Using System.Web.UI; Using System.Web.UI.WebControls; Using BLL; Public partial class RegisterOK:System.Web.UI.Page {User user = new user (); protected void Page_Load (object sender, Eve Ntargs e) {if (! IsPostBack) {String lb = request["lb"]; string username = request["username"]; string password = request["password"]; str ing question = request["question"]; String answer = request["Answer"]; String xqcode = request["Xqcode"]; String realname = request["Realname"]; string sex = request["Sex"]; String Tel = request["Tel"]; String qqmsn = request["Qqmsn"]; string email = request["email"]; string address = request["Address"]; if (lb = = "CheckName") {Response.Write (user. Checkusername (username)); } if (lb = = "Reguser") {string name = user. Checkusername (username); if (name = = "Congratulations, this user name can be registered! ") {User. ADD (username, password, question, answer, Xqcode, realname, Sex, tel, qqmsn, email, address); Response.Write("Success"); } else {Response.Write ("fail");}} } } }
Note: The registerok.aspx page must empty all HTML code, such as only <%@ page language= "C #" autoeventwireup= "true" codefile= " RegisterOK.aspx.cs "inherits=" Registerok "%>.