Validate CAPTCHA in another file like an .asmx

2 posts, 0 answers
  1. reza meshksar
    reza meshksar avatar
    4 posts
    Member since:
    Dec 2005

    Posted 12 Aug 2010 Link to this post

    This is my requirement.
    I have a form with Captcha and by clicking on submit button a JQuery function calls a web method of an asmx web service using Ajax.
    How can I validate Captcha value in that web method? Because it is not the code behind, I cannot use Page.IsValid method.
    If the Captcha value is stored in a session variable, since both my web page and asmx file are at the same HTTPContext I can read it and validate it.
    Thanks in advance,
  2. Pero
    Pero avatar
    1156 posts

    Posted 17 Aug 2010 Link to this post

    Hi Reza,

    You can get the text code of the Captcha using the RadCaptcha.CaptchaImage.Text property. The following example gets the code in the Page_Load and sets it to the Text property of a Button:

    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head runat="server">
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="ScriptManager1" runat="server">
            <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Invalid Code" ValidationGroup="Group"
            <asp:Button ID="Button1" runat="server" Text="Validate Code" ValidationGroup="Group" />

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    public partial class Default_Captcha : System.Web.UI.Page
        protected void Page_Load(object sender, EventArgs e)
            Button1.Text = RadCaptcha1.CaptchaImage.Text;

    Similarly you can store the value in the Session and then compare it to the code entered by the user.

    Sincerely yours,
    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
  3. DevCraft R3 2016 release webinar banner
Back to Top