ASP. NET uses ICallbackEventHandler to implement refresh Verification

Source: Internet
Author: User

 

C # code

Public partial class _ Default: System. Web. UI. Page, ICallbackEventHandler
...{
Private string result;

Protected void Page_Load (object sender, EventArgs e)
...{


If (! Page. IsPostBack)
...{
String cbReference = Page. clientScript. getCallbackEventReference (this, "text", "ReceiveServerData", ""); // gets a reference to a client function. When this function is called, calls back a client that starts a server-side event.
String callbackScript = "function dos (text) {" + cbReference + ";}"; // Method for registering a client
Page. ClientScript. RegisterClientScriptBlock (this. GetType (), "dos", callbackScript, true );








}


}
Public void RaiseCallbackEvent (string text)
...{


If (text [0] = 'C ')
...{
String checkcode = (string) Session ["validateCode"];
String j = text. Substring (1 );
Checkcode = checkcode. ToLower ();
J = j. ToLower ();
If (j = checkcode)
Result = "ctrue ";
Else
Result = "cfalse ";

}
Else if (text [0] = 'E ')
...{
String j = text. Substring (1 );
LinkDataBase myLink = new LinkDataBase ();
If (mylink. checkemail (j) = 1)
Result = "efalse ";
Else
Result = "etrue ";

}
Else if (Text [0] = 'U ')
...{
String J = text. substring (1 );
Linkdatabase mylink = new linkdatabase ();
If (mylink. checkuser (j) = 1)
Result = "ufalse ";
Else
Result = "utrue ";
}
}
Public String getcallbackresult ()
...{

Return result;
}



}

 

Add the following functions to javascript:

Function compute eserverdata (text)
...{

If (text = "cfalse ")
...{
Checkvalidatecode = "false2 ";
Setcheckvalidatecode (checkvalidatecode );

}
Else if (text = "ctrue ")
...{

Checkvalidatecode = "true ";
Setcheckvalidatecode (checkvalidatecode );
}
Else if (text = "etrue ")
...{
Checkemail = "true ";
Setcheckemail (checkemail );
}
Else if (text = "efalse ")
...{
Checkemail = "false3 ";
Setcheckemail (checkemail );
}
Else if (text = "ufalse ")
...{
Checkuser = "false4 ";
Setcheckuser (checkuser );
}
Else if (text = "utrue ")
...{
Checkuser = "true ";
Setcheckuser (checkuser );
}
Checking = false;

}

 

 

Finally, it is called using dos (str) in Javascript.

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.