I am using Google recaptcha in one of our projects. I added the recaptcha control in aspx page. Now i want to validate the value entered in recaptcha that is whether it is correct or not. How can i done it in a button click event? I am using c#.
Asked
Active
Viewed 8,051 times
2
-
Do you mean you're using [Google's ASP.NET control](http://code.google.com/p/recaptcha/downloads/list?q=label:aspnetlib-Latest)? Or are you embedding the captcha script on your page yourself? – Rup Apr 28 '11 at 11:42
-
@Rup: Yes, I am using google recaptcha. For this first added the Recaptcha.dll and then added the recaptcha control – Mahesh KP Apr 28 '11 at 12:12
4 Answers
5
if(Page.IsValid) //Will be true if captcha text is correct otherwise it will be false
{
//***your code****
}
Edit:
call
Page.Validate()
before checking condition

Muhammad Akhtar
- 51,913
- 37
- 138
- 191
-
2Its not working in Page.IsValid. It always returns true. When i used recaptcha.validate() and after that when checked recaptcha.IsValid its working. But i am not sure whether its the right method – Mahesh KP Apr 28 '11 at 12:14
-
1Yes, that's more or less correct: you generally call `Page.Validate` which checks all the controls on the page. From the [IsValid MSDN](http://msdn.microsoft.com/en-us/library/system.web.ui.page.isvalid.aspx): "You should check this property only after you have called the Page.Validate method, or set the CausesValidation property to true in the OnServerClick event handler for an ASP.NET server control that initiates form processing." – Rup Apr 28 '11 at 12:17
-
1@Rup: so if i want to validate the recaptcha only and not all the controls, then can i use recaptcha.validate and recaptcha.IsValid. – Mahesh KP Apr 30 '11 at 04:07
2
Apparently it doesn't work with ASP.NET ValidationGroups. If you have a ValidationGroup, you need to call recaptcha.Validate() manually before checking recaptcha.IsValid or Page.IsValid.

Mike McG
- 21
- 1