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