Skip to content

Instantly share code, notes, and snippets.

@csalazar
Created November 18, 2012 23:46
Show Gist options
  • Save csalazar/4108209 to your computer and use it in GitHub Desktop.
Save csalazar/4108209 to your computer and use it in GitHub Desktop.
Page_Load method in Default.asp.cs
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