CopyCode The Code is as follows: // 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 () },< br> datatype: 'html',
Timeout: 1000,
error: function () {alert ('an unknown error occurs, please contact QQ 6434789. ') ;},
success: function (data) {
If (Data = "sorry, this user name has been registered! ") {
MSG. classname = "d_err";
MSG. innerhtml = data;
$ ("# hiddencheckname "). val ("no");
}< br> If (Data = "congratulations, this user name can be registered! ") {
MSG. classname = "d_ OK";
MSG. innerhtml = data;
$ ("# hiddencheckname "). val ("yes");
}< br> If (Data = "this user name cannot be Chinese! ") {
MSG. classname = "d_err";
MSG. innerhtml = data;
$ ("# hiddencheckname "). val ("no");
}< br> If (Data = "Enter the user name! ") {
MSG. classname = "d_err";
MSG. innerhtml = data;
$ ("# hiddencheckname "). val ("no");
}< BR >});
}< BR >}
Function checkn (){
VaR MSG = Document. getelementbyid ("d_username ");
VaR chk = true;
If (checkischinese (document. getelementbyid ("username"). Value )){
MSG. classname = "d_err ";
MSG. innerhtml = "the user name cannot be Chinese! ";
Chk = false;
}
If (document. getelementbyid ("username"). value. Length <4 ){
MSG. classname = "d_err ";
MSG. innerhtml = "the user name cannot be less than 4 characters! ";
Chk = false;
}
Return chk;
}
Function chk_reguser (){
VaR chk = true
// If (! Checkname () {chk = false;} // variables assigned by jquery cannot be shared with the variables in JS, so success: function (data) the variables defined in {} are not the same as those in the js code, so I am looking for a relatively (informal) method, add hidden input to HTML and set $ ("# hiddencheckname") in Js "). val ("no ");
If (! Checkn () {chk = false ;}
If ($ ("# hiddencheckname"). Val () = "no") {chk = false;} // This is to determine its
If (! Checkpwd () {chk = false;} // similar to checkn (), the elements in the form are verified.
If (! Checkpwd1 () {chk = false ;}
If (! Checkquestion () {chk = false ;}
If (! Checkanswer () {chk = false ;}
If (! Checkxq () {chk = false ;}
If (! Checkrealname () {chk = false ;}
If (! Checktel () {chk = false ;}
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 ('unknown error, please contact QQ: 6434789. ');},
Success: function (data ){
If (Data = "success "){
Alert ("registration successful! ");
Window. Location. href = "/member/index. aspx ";
}
Else {
Alert ("registration failed because the user name has been registered! ");
}
}
});
Return (true );
}
Return (false );
}
// Html page
Just make a form like thisCopy codeThe Code is as follows: <input id = "username" type = "text" onblur = "checkname ()"/>
<Div class = d_default id = d_username> enter four or more English characters or numbers! </Div>
<Input id = "button_ OK" type = "button" onclick = "Return chk_reguser ();"/>
// Registerok. aspx. CSCopy codeThe Code is as follows: using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using BLL;
Public parttial class registerok: system. Web. UI. Page
{
User user = new user ();
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
String lB = request ["LB"];
String username = request ["username"];
String Password = request ["password"];
String 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: registerok. the ASPX page must clear all HTML code, for example, only <% @ page Language = "C #" autoeventwireup = "true" codefile = "registerok. aspx. CS "inherits =" registerok "%>.