This is a migrated thread and some comments may be shown as answers.

RadCaptcha Not Validating

7 Answers 459 Views
Captcha
This is a migrated thread and some comments may be shown as answers.
Prathap Narravula
Top achievements
Rank 1
Prathap Narravula asked on 02 Nov 2010, 12:43 PM

Hi,

I am doing booking form page for the members with Radcaptch validation.

 

<telerik:RadCaptcha ID="RadCaptcha1" runat="server" ValidationGroup="SubmitInfo"

 

 

   ErrorMessage="The code you entered is not valid." Display="Dynamic">

 

 

</telerik:RadCaptcha>

 


I given the ValidationGroup Property to textbox requiredfield validation and  submit button also.

RequiredFieldValidator is validating for textbox but radcaptch is not validating

 

<asp:TextBox ID="txtemail" runat="server"></asp:TextBox>

 

 

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ValidationGroup="SubmitInfo"

 

 

runat="server" ControlToValidate="txtemail" ErrorMessage="Enter Email"></asp:RequiredFieldValidator>

 



 

<asp:Button ID="btnbooking" runat="server" ValidationGroup="SubmitInfo" Text="Submit"

 

 

OnClick="btnbooking_Click" />


Please help in the issue which i stucked for 3 days.

Urgent reply highly appreciable

Regards,
Prathap Narravula



 

7 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 04 Nov 2010, 10:13 AM
Hi Prathap,

Could you please explain in more detail what do you mean by "RadCaptcha is not validating"?

Please note that the RadCaptcha control does not support client-side validation. A post back to the server is needed in order for the Captcha to perform validation. So if at first sight it seems that the Captcha does not validate, but the other validators do, it is because the they also support client-side validation and prevent the WebForm from submitting if the page is not valid.

In case you check for the IsValid property on the server, in the button's click event handler, then you should call RadCaptcha's Validate and Page's Validate(ValidationGroup), to be sure that validation has occurred, before checking the IsValid flag.

Note that if you dynamically create the Captcha control, you must add it to the page on every postback, and before the ViewState is loaded. That is if you add the control in the Page.Load, it is too late, because the ViewState has been loaded, and the Captcha will always invalidate the code. Our suggestion is to use the Page.Init method instead.

All the best,
Pero
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Danny
Top achievements
Rank 2
answered on 22 Feb 2012, 05:28 PM

You must:

  • Enter value for ErrorMessage property
  • ValidationGroup must match the ValidationGroup name on the ValidationSummary and the button that causes the PostBack.
  • The button causing the PostBack must have CausesValidation set to true.

 

Remember that the RadCaptcha does NOT have client-side validation like many of the other controls on your page.  You will not see RadCaptcha validation until the page is posted back to the server.   Other controls that have client-side validation will warn user of errors without posting the page back to the server which means your RadCaptcha wont validate at that point.   This may give the appearance that your RadCaptcha validation is not working. 

www.BlueCanyonSoftware.com 

0
Glenn
Top achievements
Rank 1
answered on 30 Aug 2013, 02:52 PM
Is there a way to use the RequiredFieldValidator?  I would like to prevent a postback if the user hasn't entered anything into the captcha code text box.
0
Shinu
Top achievements
Rank 2
answered on 02 Sep 2013, 06:29 AM
Hi Glenn,

You can validate the RadCaptcha via a custom RadTextBox and give an ASP RequiredFieldValidator to the particular RadTextBox to prevent the postback if it is empty. The custom RadTextBox for RadCaptcha can be given by

1. Setting the propery CaptchaImage.RenderImageOnly to true to render only the captcha image without the TextBox and Label of the control.

2. Setting the property ValidatedTextBoxID to the ID of the RadTextBox which you want to use for entering the RadCaptcha code.

Please have a look at the following code I tried which works fine at my end.

ASPX:

<telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Invalid Captcha"
    IgnoreCase="true" CaptchaImage-RenderImageOnly="true" ValidatedTextBoxID="RadTextBox1">
</telerik:RadCaptcha>
<br />
<telerik:RadTextBox ID="RadTextBox1" runat="server">
</telerik:RadTextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*"
    ForeColor="Red" ControlToValidate="RadTextBox1"></asp:RequiredFieldValidator>
<br />
<telerik:RadButton ID="RadButton1" runat="server" Text="Submit" CausesValidation="true"
    OnClick="RadButton1_Click">
</telerik:RadButton>

Thanks,
Shinu.
0
Glenn
Top achievements
Rank 1
answered on 03 Sep 2013, 01:49 PM
I tried that and what happens is that the textbox gets blanked out before the requiredfieldvalidator fires so it never actually does a postback.  I was able to add a "hidden" textbox and add an onblur event to the actual textbox to copy the code to the hidden one.  I tied the requiredfieldvalidator to the hidden textbox.  That was the only way I could get it to work.
0
Slav
Telerik team
answered on 06 Sep 2013, 07:58 AM
Hello Glenn,

Usually the validated textbox gets cleared after the postback, so it is strange that this happens even before the RequiredFieldValidator validates the input. I would suggest checking if there is a custom client-side script that clears the textbox before validation. Also, you can send a fully runnable sample that isolates your scenario and I will do my best to locate the cause of the issue.

Regards,
Slav
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Dhamodharan
Top achievements
Rank 1
answered on 20 Sep 2013, 06:10 AM
Hi Glenn,
please try the following coding on client button clicking event.
Declare a label - lblCaptchaErr to display the error msg
Assume your Captcha named as RadCaptcha1

On button clicking event
   if (document.getElementById('RadCaptcha1_CaptchaTextBox').value == "") {                   
                    document.getElementById('<%= lblCaptchaErr.ClientID %>').innerHTML = "Please enter the Captcha Code";
                    args.set_cancel(true);
                }



Thanks


Tags
Captcha
Asked by
Prathap Narravula
Top achievements
Rank 1
Answers by
Pero
Telerik team
Danny
Top achievements
Rank 2
Glenn
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Slav
Telerik team
Dhamodharan
Top achievements
Rank 1
Share this question
or