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

Validate CAPTCHA in another file like an .asmx

1 Answer 65 Views
This is a migrated thread and some comments may be shown as answers.
reza meshksar
Top achievements
Rank 1
reza meshksar asked on 12 Aug 2010, 04:44 PM
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,

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 17 Aug 2010, 01:58 PM
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
Asked by
reza meshksar
Top achievements
Rank 1
Answers by
Telerik team
Share this question