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

Validate CAPTCHA in another file like an .asmx

1 Answer 51 Views
Captcha
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
Hi,
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,
Reza.

1 Answer, 1 is accepted

Sort by
0
Pero
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <telerik:RadScriptManager ID="ScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Invalid Code" ValidationGroup="Group"
            ForeColor="Red">
        </telerik:RadCaptcha>
        <asp:Button ID="Button1" runat="server" Text="Validate Code" ValidationGroup="Group" />
    </div>
    </form>
</body>
</html>

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,
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
Tags
Captcha
Asked by
reza meshksar
Top achievements
Rank 1
Answers by
Pero
Telerik team
Share this question
or