Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Captcha / Generate New CaptchaImage







  • Generate New Image and Validate a Custom TextBox


    This example demonstrates two important features of the RadCaptcha control:

    • Refresh-CaptchaImage Functionality - The RadCapthca gives the possibility to refresh the CaptchaImage if the current one cannot be read. Simply set the EnableRefreshImage property to true and a LinkButton, that generates new images, will be rendered.
    • Validate a Custom TextBox and Render only the CaptchaImage - By setting the CaptchaImage.RenderImageOnly to true you can choose to render only the CaptchaImage without the RadCapthca TextBox and Label. Set the ValidatedTextBoxID to the ID of the TextBox which you want to be validated by the RadCaptcha.


Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="c#" AutoEventWireup="true" Inherits="Telerik.Web.Examples.Captcha.RefreshImage.DefaultCS"
        CodeFile="DefaultCS.aspx.cs" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server" />
        <style type="text/css">
            .rcRefreshImage
            {
                padding-left: 25px;
                padding-right: 25px;
            }
            .imageClass
            {
                padding-top: 10px;
                padding-bottom: 10px;
            }
            .module1
            {
                background-color: #dff3ff;
                border: 1px solid #c6e1f2;
                padding: 15px 0 15px 0;
            }
        </style>

        <script type="text/javascript">
            function pageLoad()
            {
                //Disable autoComplete
                $get("txtRadCaptcha").setAttribute("autoComplete", "off");
            }
        </script>

    </head>
    <body class="BODY">
        <form id="Form2" method="post" runat="server" defaultbutton="btnValidate">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="c#" ShowSkinChooser="false" />
        <telerik:RadScriptManager ID="ScriptManager" runat="server" />
        <telerik:RadFormDecorator ID="FormDecorator1" runat="server" DecoratedControls="All">
        </telerik:RadFormDecorator>
        <fieldset class="module1">
            <div style="float: left; padding-left: 50px">
                <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="Page not valid. The code you entered is not valid."
                    ValidationGroup="Group">
                    <CaptchaImage ImageCssClass="imageClass" />
                </telerik:RadCaptcha>
                <div style="margin-top: 15px;">
                    <asp:Button ID="btnValidate" runat="server" Text="Verify Code" ValidationGroup="Group" />
                </div>
            </div>
            <div style="float: right; padding-right: 50px">
                <br />
    <asp:CheckBox ID="cbEnableRefreshImage" runat="server" Text="Enable Refresh-CaptchaImage Functionality"
    AutoPostBack="true" OnCheckedChanged="EnableRefreshCaptchaImage" />

                <br />
    <asp:CheckBox ID="cbCustomTextBox" runat="server" AutoPostBack="true" Text="Use this TextBox to enter the RadCaptcha Code"
    OnCheckedChanged="EnableCustomTextBoxValidation" /><br />

                <asp:TextBox ID="txtRadCaptcha" runat="server" Enabled="false" MaxLength="5"></asp:TextBox>
            </div>
        </fieldset>
        <br />
        <br />
        <telerik:RadAjaxManager ID="ajaxManager" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="cbCustomTextBox" EventName="CheckedChanged">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="cbCustomTextBox" />
                        <telerik:AjaxUpdatedControl ControlID="txtRadCaptcha" />
                        <telerik:AjaxUpdatedControl ControlID="RadCaptcha1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="cbEnableRefreshImage" EventName="CheckedChanged">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="cbEnableRefreshImage" />
                        <telerik:AjaxUpdatedControl ControlID="RadCaptcha1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <qsf:Footer runat="server" ID="Footer1" ShowCodeViewer="true" />
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451