Click to refresh the verification code in ASP. NET

Source: Internet
Author: User

I. Verification Code Generation

When I was developing a. Net webpage, I found that when I used the verification code, I provided a way to "not see clearly, change one". I am also a mediocre person, so I also set it like this:

1. Number. aspx indicates the verification code generation.Code.

2. Refresh () is the image switching function.

In this example, "document. all. check. src = ''" simply uses check. the "src" reconfiguration does not support image update and verification code re-generation. Later, through a variety of experiments, we found that the parameter configuration transfer can be sent to 1. the ASPX page is called again.

Use. Net to generate random numbers. When you click "Pass Parameter" to refresh the image, the page is re-activated:

Function refresh (){
VaR num = math. Ceil (math. Random () * 100 );

Document. All. Check. src = "./number. aspx? Num = "+ num;
}

Click image update for the verification code.

 

2. Ajax obtains the session verification code information.

1. Call the following code in page_load.

Ajaxpro. Utility. registertypeforajax (typeof (Class));

2. The following configuration is required when the session is called.

[Ajaxpro. ajaxmethod (ajaxpro. httpsessionstaterequirement. Read)]
Public String Ajax ()
{
If (session ["Number"]! = NULL ){
Return session ["Number"]. tostring ();
} Else {
Return "";
}
}

3. Call the Ajax function in Js.

VaR num = ajaxspace.Class. Ajax (). value;

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.