Invisible textbox

6 posts, 0 answers
  1. Saravanan
    Saravanan avatar
    26 posts
    Member since:
    Mar 2013

    Posted 17 Jul 2013 Link to this post

    Hi

    Can anyone help with a simple code to implement radcaptcha with invisible textbox? I saw the demo code but I got a bit confused there. I cant figure out the thing they are doing there.

    Thanks
    Saravanan
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 Jul 2013 Link to this post

    Hi

    Please have a look into the following sample code i tried which works fine as expected.

    ASPX:
    <telerik:RadTextBox ID="RadTextBox1" runat="server" Label="UserName : ">
    </telerik:RadTextBox>
    <telerik:RadTextBox ID="RadTextBox2" runat="server" Label="Password : " TextMode="Password">
    </telerik:RadTextBox>
    <telerik:RadCaptcha ID="RadCaptcha1" runat="server" ProtectionMode="InvisibleTextBox">
    </telerik:RadCaptcha>
    <asp:Label ID="Label1" runat="server">
    </asp:Label>
    <telerik:RadButton ID="btnVerify" runat="server" Text="Submit" OnClick="btnVerify_Click">
    </telerik:RadButton>
    <br />
    <br />
    <asp:CheckBox ID="CheckBox1" runat="server" Text="Fill the Invisible TextBox to invalidate page"
        onclick="fillInvisibleTextBox(this);" />

    JavaScript:
    <script type="text/javascript">
        function fillInvisibleTextBox(sender) {
            var invisibleTextBox = $get("<%=RadCaptcha1.ClientID %>_InvisibleTextBox");
            if (sender.checked) {
                invisibleTextBox.value = "SomeText";
            }
            else {
                invisibleTextBox.value = "";
            }
        }
    </script>

    C#:
    protected void btnVerify_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            Label1.ForeColor = System.Drawing.Color.Green;
            Label1.Text = "Page submitted successfully!<br/><br/>";
        }
        else
        {
            Label1.ForeColor = System.Drawing.Color.Red;
            Label1.Text = "Page not submittes. Invisible textbox was filled by a bot!<br/><br/>";
        }
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Saravanan
    Saravanan avatar
    26 posts
    Member since:
    Mar 2013

    Posted 19 Sep 2013 Link to this post

    Hi shinu

    Is it possible to get the captcha text in code behind? I tried but I am getting some invalid characters not same as the one in the captcha text.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Sep 2013 Link to this post

    Hi Saravanan,

    It is possible to get the RadCaptcha text in code behind. Suppose you are trying to access the RadCaptcha text in code behind you wont get the exact text displayed in the RadCaptcha image. This is because when the control post back, the RadCaptcha is updated with a new captcha image and the characters that are displayed in the updated image will be received in your C# code and hence you get some new characters which you described as invalid. You can try the following code to access the captcha text.

    C#:
    protected void Page_Init(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["CaptchaCode"] = RadCaptcha1.CaptchaImage.Text;
        }
    }

    protected void RadButton1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>alert('" + Session["CaptchaCode"].ToString() + "')</script>");
        //your code
     
        Session["CaptchaCode"] = RadCaptcha1.CaptchaImage.Text; //updating with new captcha text.
    }

    Hope this helps,
    Shinu.
  6. Saravanan
    Saravanan avatar
    26 posts
    Member since:
    Mar 2013

    Posted 20 Sep 2013 Link to this post

    Hi shinu

    Instead of using a label, is it possible to add an icon to generate a new captcha image?
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 20 Sep 2013 Link to this post

    Hi Saravanan,

    Please have a look at the following code I tried which works fine at my end.

    ASPX:
    <telerik:RadCaptcha ID="CaptchaCode" runat="server" EnableRefreshImage="true" CaptchaLinkButtonText="<br/>">
    </telerik:RadCaptcha>

    CSS:
    <style type="text/css">
        .rcRefreshImage
        {
            background-image: url('../Images/refresh.png');
            background-repeat: no-repeat;
            margin-left: 185px;
            margin-top: -20px;
        }
    </style>

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017