Captcha enter button

2 posts, 0 answers
  1. Mike Conine
    Mike Conine avatar
    12 posts
    Member since:
    Aug 2004

    Posted 27 Jun 2009 Link to this post

    Hey Guys;

    Great start on the Captcha function.

    What is the best recommendation for hooking the Captcha submission to a keyboard enter click, rather than verify code?
  2. Pero
    Pero avatar
    1156 posts

    Posted 01 Jul 2009 Link to this post

    Hi Mike,

    Because, the RadCaptcha validates on a post back, the logical way to set the RadCaptcha validate on Enter key pressed, is to set the Enter key cause post back when it is clicked. One way to do this is by attaching an event handler to the "onkeypress" event of the RadCaptcha TextBox (the "onkeypress" event is attached dynamically to the TextBox), that will submit the form when Enter is pressed. The assumption here is that the user inputs the code as a last stage before the form is submitted. I have implemented a sample project that demonstrates the described scenario. Here is the full source code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
    <html xmlns=""
    <head runat="server"
        <style type="text/css"
                color: Green; 
                background-color: Red; 
    <body onload="bodyOnLoad()"
        <form id="form1" runat="server" method="post"
        <asp:ScriptManager ID="ScriptManager1" runat="server"
            <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ErrorMessage="RadCaptcha Error Message" ProtectionMode="Captcha"
            <br /> 
            <br /> 
        <script type="text/javascript"
            //get the client object of the RadCapthca TextBox 
            var captchaTextBox = document.getElementById('RadCaptcha1_CaptchaTextBox'); 
            function bodyOnLoad() 
                //attach an event to the textbox 
                var e = (window.event)? window.event : event; 
                captchaTextBox.attachEvent('onkeypress', function(e) { checkKeyPress(e); }); 
            function checkKeyPress(e) 
                var keypressed = null
                if (e.keyCode)  
                    keypressed = e.keyCode; 
                    keypressed = e.which; 
                //if Enter is pressed submit the form 
                if (keypressed === 13) 

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top