Check whether the user exists on the registration page (simple JQ Ajax application)

Source: Internet
Author: User

 

 

 

Step 2: place the main code of the ASP. NET Server Control (. aspx)

 

<Tr>

<Td>

Login Name:

</Td>

<Td>

<Asp: TextBox ID = "txtLoginName" runat = "server"> </asp: TextBox>

<Input type = "button" value = "whether" id = "btnExist"/>

</Td>

</Tr>

 

Step 2: reference the corresponding JQuey file (the local machine is the jquery-1.4.2.js) and extract user input values and send them to the server handler (CheckUserNameExist. ashx)

 

<Head runat = "server">

<Title> </title>

 

<Script src = "js/jquery-1.4.2.js" type = "text/javascript"> </script>

 

<Script type = "text/javascript">

$ (Function (){

$ ("# BtnExist"). click (function (){

/* Note that the server control must be obtained using ClientID */

Var loginname = $ ("# <% = txtLoginName. ClientID %>"). val ();

 

// Send a post request to CheckUserNameExist. ashx.

 

$. Post ("ashx/CheckUserNameExist. ashx", {"loginname": loginname}, function (data, status ){

If (status! = "Success "){

Alert ('ajax loading failed ');

Return;

}

If (data = "true "){

Alert ("User already exists ");

}

Else if (data = "false "){

Alert ("You're lucky, register now ");

}

Else {

Alert ("what's the situation !! ");

}

});

});

})

</Script>

 

</Head>

 

 

Step 2: Create the CheckUserNameExist. ashx general processing program file and write the background CheckUserNameExist. ashx, as shown below:

 

<Span style = "font-size: 16px;"> public void ProcessRequest (HttpContext context)

{

Context. Response. ContentType = "text/plain ";

String strLoginName = context. Request ["loginname"];

// Check whether the user exists in the Database

Bool bExist = UserBLL. IsExistUser (strLoginName );

If (bExist)

{

Context. Response. Write ("true ");

}

Else

{

Context. Response. Write ("false ");

}

} </Span>

 

 

 

<P>

</P>

 

From hi_dzj's column

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.