Ajax registration framework

Source: Internet
Author: User

Asp.net verifies some registration information on the client through the verification control, which has certain restrictions on the verification scope. For example, whether the user name is repeated and all user information is stored in the server database. Therefore, you need to access the server and the authentication control cannot be implemented. Based on the implementation principle of common dynamic web pages, the client submits information, the server receives information for corresponding processing, and then returns data to the client, the registration function cannot implement real-time verification of refreshing registration information.

Ajax provides asynchronous information exchange between the client and the server for real-time dynamic verification of registration information. Here we use the ajaxpro. NET Framework. The user name verification function is described below:

1 userregister. aspx:

< ASP: textbox ID = " Txtusername " Runat = " Server " Height = " 21px " Onkeyup = " Verifyusername (this. value) "   > < / ASP: textbox>

 

Function Verifyusername (name)
{
Userregister. getreturncode (name, isusernameexist_callback );
}

Userregister is the registration page name, And getreturncode is the background C #Code

The parameter name is the username entered in the current editing box, And isusernameexist_callback is the function that processes the information returned by getreturncode.

 

Code
Function Isusernameexist_callback (RES)
{
VaRMSG=Document. getelementbyid ("<% = Lblmsgusername. clientid %>");//Lblmsgusername: displays verification information
VaRBret=Res. value;//Extract the value returned by the server

Switch(BRET)//Displays the corresponding verification information based on the returned value.
{
Case "Valid" :
MSG. innerhtml= 'The input is valid.' ;
Break ;
Case "Exist" :
MSG. innerhtml= 'The user name already exists. Please use another Login User Name!' ;
Break ;
Case "Novalid" :
MSG. innerhtml= 'The username must be in the range of 3 to 15!' ;
Break ;
Case "Empty" :
MSG. innerhtml= 'Cannot be blank!' ;
Break ;
}
}

2 userregister. aspx. CS:

Code
[Ajaxpro. ajaxmethod]//Ajaxpro. Net method declaration
Public StringGetreturncode (String Strval)
{
If(Strval. Equals (String . Empty ))
{
Return "Empty" ;
}
Else If(!Isvalidusername (strval ))//Verify username input format
{
Return "Novalid" ;
}
Else If(Isusernameexist (strval ))//Verify that this user name exists in the Database
{
Return "Exist" ;
}
Else
{
Return "Valid";//Valid
}
}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.