Wednesday, 24 April 2013

Working Captcha Image



How to Add a Captcha Image in ASP.NET Application


There are some steps to Add Captcha image in Asp.NET Application. You can downloadwhole application from the below link. Please follow steps one by one which is given below.
Step1:- First create ASP.NET page (Default.aspx) in visual studio 2010. Now click the below link to download the captcha.dll file.
see captcha.dll file:-

Step2:-Now Open Solution Explorer ->Add new Folder(Bin)->open the captcha.dll file->copy all the file -> Now paste it in Bin Folder
see it:-
Step3:- Now Write the code for captcha control in source file.
see it:-

Step4:-  Now Drag and Drop Text-box,Button, Label and Validation control control onDefault.aspx page from the Toolbox.which is shown below:-
see it:-

Step5:- Now Double click on Button control(Verify) and write the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        captcha1.ValidateCaptcha(TextBox2.Text.Trim());
        if (captcha1.UserValidated)
        {
          Label1.ForeColor = System.Drawing.Color.Green;
          Label1.Text = "You have Entered Valid Captcha Characters";
        }
        else
        {
            Label1.ForeColor = System.Drawing.Color.Red;
            Label1.Text = "You have Entered InValid Captcha Characters please Enter again";
        }
    }
}

see it:-


Step6:- Now open the web.config file and write the following code.

   
  
see it:-


Step7:- Run the Application (press F5).
see
OUTPUT:-

  • when we Entered correct captcha image In Text-Box and click Verify Button.

  • when we Entered Incorrect captcha image In Text-Box and click Verify Button.

No comments:

Post a Comment