views:

2333

answers:

3

I am using the ASP.Net plugin and control provided by reCAPTCHA. I can successfully get the control to work if the submit button on the web form is not in a validationgroup. There is no validationgroup attribute for the reCAPTCHA control.

Has anybody had any success with this or any solutions to get the reCAPTCHA control to work when there is a validationgroup on the web form?

+1  A: 

The reCAPTCHA ASP.NET plug-in is written to be backward-compatible with ASP.NET 1.1, which means the ValidationGroup concept (which is new in ASP.NET 2.0) is not supported. But the plug-in comes with downloadable source code, so you can modify it yourself to support ValidationGroup.

In ASP.NET 2.0, validators should inherit from BaseValidator and implement IValidator, which means you should change the RecaptchaControl type to inherit from BaseValidator instead of WebControl. You will then have to modify the code a bit to implement all methods and properties defined in BaseValidator. Then you can use this new control on your page instead, which now supports ValidationGroup.

bzlm
Hi bzlm. I've done the above, but have two problems:1) BaseValidator also requires you to implement the abstract EvaluateIsValid() method (reutrning the IsValid property with it doesn't work).2) The reCaptcha control then needs the ControlToValidate property filled.Can you help with any of those? Thanks.
Nick
I commented out the IValidator implementation that is giving by the reCAPTCHA plugin, and pushed that logic into the EvaluateIsValid() method. I also bypassed the ControlToValidate property in code since it doesn't seem to apply in this scenario.One other point to realize is that you should handle situations where validate is called more than once on the page. You need to ensure that you don't actually call the reCAPTCHA API twice as this will invalidate the control. Hope this helps.
rifferte
Hi, would it be possible to get a bit more info on how to do this? Or has someone already got a completed project they can share?
TimS
+1  A: 

You can add CustomValidator, implement OnServerValidate that would validate the ReCAPTCHA data. CustomValidator can be assigned to any ValidatorGroup.

Vitalik
Nice solution. You just need to check recaptcha.IsValid in your OnServerValidate method then. Very simple!
A: 

protected void Button1_Click(object sender, EventArgs e) { //Do nothing
} protected void Button2_Click(object sender, EventArgs e) { CaptchaControl1.Enabled = false;
}

protected void Page_PreRender(object sender, EventArgs e)
{
    CaptchaControl1.Enabled = true;
}
Mani