Created
November 18, 2012 23:46
-
-
Save csalazar/4108209 to your computer and use it in GitHub Desktop.
Page_Load method in Default.asp.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void Page_Load(object sender, System.EventArgs e) | |
{ | |
if (!this.IsPostBack) | |
// Create a random code and store it in the Session object. | |
this.Session["CaptchaImageText"] = GenerateRandomCode(); | |
else | |
{ | |
// On a postback, check the user input. | |
if (this.CodeNumberTextBox.Text == this.Session["CaptchaImageText"].ToString()) | |
{ | |
// Display an informational message. | |
this.MessageLabel.CssClass = "info"; | |
this.MessageLabel.Text = "Correct!"; | |
} | |
else | |
{ | |
// Display an error message. | |
this.MessageLabel.CssClass = "error"; | |
this.MessageLabel.Text = "ERROR: Incorrect, try again."; | |
// Clear the input and create a new random code. | |
this.CodeNumberTextBox.Text = ""; | |
this.Session["CaptchaImageText"] = GenerateRandomCode(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment