Tuesday, 15 January 2013 13:56

how to add captcha in asp.net page

Written by 
Rate this item
(0 votes)

A CAPTCHA is a program which tells whether its user
is human or computers.

follow the steps below to add captcha in your web form
easily -

1.download the library from here -
http://code.google.com/p/recaptcha/downloads/list?q=label:aspnetlib-Latest

2.then add a reference of the downloaded Recaptcha.dll
file to your website

3.then insert the recaptcha control to your aspx page
by adding at top-
<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>

then under form tag -
<recaptcha:RecaptchaControl ID="recaptcha" runat="server"
PublicKey="" PrivateKey=""/>

4.then sign up for API key here -
http://recaptcha.net/api/getkey?app=aspnet.
after that place the public key and private key
in the PublicKey and PrivateKey properties in the above code

5.add the follwing lines too under your form tag in your page -

<form runat="server">
<asp:Label Visible=false ID="lblResult" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</form>

6.add the following button click method in code behind file
of your page -
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
lblResult.Text = "You Got It!";
}
else
{
lblResult.Text = "Incorrect";
}}

now test your page recaptcha.also read the following post
to overcome updatepanel problem -
http://weblogs.asp.net/alessandro/archive/2008/09/09/
automatically-reload-recaptcha-when-postingback-via-a-partial-refresh-updatepanel.aspx

Read 2020 times
Super User

Email This email address is being protected from spambots. You need JavaScript enabled to view it.
Login to post comments