recaptcha in .net with submit button using ValidationGroup

354 views
Skip to first unread message

james

unread,
Apr 15, 2009, 11:16:56 AM4/15/09
to reCAPTCHA
Please help.

I have the recaptcha control installed successfully. It works
fine....but not when I apply a ValidationGroup to the submit button
(not to the recaptcha control).

Here's the setup: I have the recaptcha control and two asp buttons
Button1 and Button2. Button1 has no validationgroup and the Button2
does. When I click on Button1 the control validates. But when I click
on Button2 (which has the validationgroup), the control never
validates...it is always false. I have tried both Page.IsValid and
this.recaptcha.IsValid but both always return false.

Can someone help me?

Here is my code I've been testing with: (yes I have the proper keys
applied in my application)

<asp:TextBox ID="txtName" runat="server" MaxLength="50"
Width="400" ValidationGroup="ValidationForm"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
runat="server" ErrorMessage="Name is required."
ControlToValidate="txtName" ValidationGroup="ValidationForm"
SetFocusOnError="True" Display="Dynamic">*</
asp:RequiredFieldValidator>
<br />

<recaptcha:RecaptchaControl
ID="recaptcha"
runat="server"
Theme="white"

PublicKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
PrivateKey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
/>


<asp:Button ID="Button1" runat="server" Text="Valid No group"
CssClass="button_gray" OnClick="Button1_Click" Visible="true" />
<asp:Button ID="Button2" runat="server" Text="Valid"
CssClass="button_gray" OnClick="Button2_Click" Visible="true"
CausesValidation="true" ValidationGroup="ValidationForm"/>


Here are the button events in the code behind:

protected void Button2_Click(object sender, EventArgs e)
{
try
{
if (Page.IsValid)
//if (this.recaptcha.IsValid == true)
{
string strThis = "yes";
}
else
{
string str = "no";
}
}
catch (Exception ex)
{
}
}

protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (Page.IsValid)
//if (this.recaptcha.IsValid == true)
{
string strThis = "yes";
}
else
{
string str = "no";
}
}
catch (Exception ex)
{
}
}

Adrian Godong

unread,
Apr 15, 2009, 11:46:49 AM4/15/09
to reca...@googlegroups.com
This is as expected, since recaptcha does not support ValidationGroup.
--
Adrian Godong
adrian...@gmail.com

james

unread,
Apr 15, 2009, 12:04:41 PM4/15/09
to reCAPTCHA
Thanks for the reply.

Is there a way around this?

I don't have a validationgroup on the recaptcha control itself...just
on the submit button. I need the ValidationGroup on the submit button
so that it validates the textboxes that are part of the group. Once
the submit button is clicked, I thought the this.recaptcha.IsValid
would validate the recaptcha control on the server side. But this
always returns false. Why is this?
> adrian.god...@gmail.com- Hide quoted text -
>
> - Show quoted text -

Adrian Godong

unread,
Apr 15, 2009, 12:18:37 PM4/15/09
to reca...@googlegroups.com
If you set a ValidationGroup, then ASP.NET/JS only validates controls
which have that specific ValidationGroup. .NET reCAPTCHA control being
derived from IValidator does not support this behaviour, thus will be
left out when any ValidationGroup-based validation is performed.

For workaround, you may manually call RecaptchaControl.Validate()
before retrieving the values of RecaptchaControl.IsValid.
--
Adrian Godong
adrian...@gmail.com

james

unread,
Apr 15, 2009, 1:00:17 PM4/15/09
to reCAPTCHA
Thanks. Yeah I didn't have this line RecaptchaControl.Validate().
After apply that it now seems to work. The weird thing is that I
remember adding that at one time and couldn't get it working. Strange.
But it seems to be working now. I'll run some more tests to make
sure.

Thanks for your help.
Reply all
Reply to author
Forward
0 new messages