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

Client-side validation

6 Answers 228 Views
Captcha
This is a migrated thread and some comments may be shown as answers.
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Fit2Page asked on 22 Jan 2010, 11:33 AM
Hi,

Is it possible to validate on the client through

<asp:CustomValidator CssClass="Error Akkoord" ValidationGroup="Weblink"  ClientValidationFunction="Captcha" Runat="server" display="none" ID="CaptchaReq"/>

<script language="javascript">
function Captcha(oSrc, args)
{
//Validate the Captcha object here
}
</script>

Thanks,
Marc



<script language="javascript">
function Captcha(oSrc, args)
{
$(document.getElementById("<%=SoortBedrijf.ClientID%>")).addClass("PaginaError");
  if ( document.getElementById("<%= SoortBedrijf.ClientID %>")!=null &&
     document.getElementById("<%= SoortBedrijf.ClientID %>").childNodes!=null)
     {
        for (var i=0;i<document.getElementById("<%= SoortBedrijf.ClientID %>").getElementsByTagName("input").length ; i++)
        {
           if ( document.getElementById("<%= SoortBedrijf.ClientID %>").getElementsByTagName("input")[i].checked )
           {
           $(document.getElementById("<%=SoortBedrijf.ClientID%>")).removeClass("PaginaError");
          args.IsValid = true;
         return true;
           }
           else
           {args.IsValid = false;
           return false;
           }
      }
   }
}
</script>   


6 Answers, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 25 Jan 2010, 12:59 PM
Hi Marc,

RadCaptcha performs only server-side validation. The RadCaptcha code cannot be accessed from the client and thus client-side validation cannot be performed.

Please do not hesitate to contact us, if you have any further questions.

Sincerely yours,
Pero
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mark Ursino
Top achievements
Rank 1
answered on 01 Feb 2010, 03:52 PM
Would it be possible to create either a web service or a handler that takes in the user input and the Captcha GUID and performs server-side validation in that? Then you could make an AJAX call to that validator and you'd achieve client-side validation from that?
0
Pero
Telerik team
answered on 04 Feb 2010, 10:03 AM
Hello Mark,

The page goes through its full life-cycle on AJAX calls: http://encosia.com/2007/10/24/are-you-making-these-3-common-aspnet-ajax-mistakes/. This means that a new RadCaptcha code will be generated but it would not be displayed on the image, since the RadCaptcha control is not updated by the AJAX call. Basically you would compare the old code with the new code and the user input will always be validated as wrong.

One more thing is that this would create additional load on the server because there would be an additional trip to the server just to validate the Captcha code.

Regards,
Pero
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Ross Presser
Top achievements
Rank 1
answered on 09 May 2011, 03:27 PM
The reason client-side validation of a CAPTCHA is desirable is because there may be RadUpload controls on the same page. If the person has mistyped the CAPTCHA, then they have to wait until all of their uploads have completed just to find out they did it wrong, and then the file uploads as well as the time taken are lost.
0
Pero
Telerik team
answered on 10 May 2011, 09:32 AM
Hi Ross,

For this scenario our suggestion is to place the RadCaptcha in an Ajax Panel and perform an Ajax request to test for the entered code. After the user has entered a valid string, then you can allow her (him) to upload the files.

Best wishes,
Pero
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 12 Dec 2013, 03:27 PM
You could check for entry into the captcha textbox using jquery:

<telerik:RadCaptcha runat="server" ID="rcCode"></telerik:RadCaptcha>

<asp:CustomValidator runat="server" ID="cusCode" ControlToValidate="DummyTextBox" ClientValidationFunction="ValidateCaptchaEntry"></asp:CustomValidator>

<asp:ValidationSummary runat="server"     ID="vs" ShowMessageBox="true" ShowSummary="false" />

        function ValidateCaptchaEntry(sender, args) {
            var formValid = true;
            if ($("[id$='rcCode_CaptchaTextBox']").val().length == 0) {
                sender.errormessage = 'Repeat code';
                formValid = false;
            }
            args.IsValid = formValid;
        }
Tags
Captcha
Asked by
Fit2Page
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Pero
Telerik team
Mark Ursino
Top achievements
Rank 1
Ross Presser
Top achievements
Rank 1
Morten
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or