?
Solved

Make reCaptcha display in form using updatepanel

Posted on 2013-10-25
3
Medium Priority
?
1,342 Views
Last Modified: 2013-10-26
Hi!
I need to display the Google reCaptcha using Ajax Update Panel if 3 bad logins are made. I'm using ASP.net Framework 4 with updatepanel.



The steps are this

1) User enter to my webpage

2) He enter his user (harry) and password (potter)

3) If he enter username and password wrong 3 times then reCaptcha will appears

The problem: when the updatepanel make the postback to add the reCaptcha it never appears! If I press F5 (normal postback) it appears :(

Thank you!!!

<%@ Page Language="vb" %>

<%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="VB" runat="server">
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        
        ActivateCaptchaIfBadLogins()
        
    End Sub
    
    Private Sub ActivateCaptchaIfBadLogins()
        
        If txtbadlogins.Text >= 3 Then
            divRecaptcha.Visible = True
        End If
        
    End Sub
    

    Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
        If Not IsValid AndAlso Not recaptcha.IsValid Then
            txtbadlogins.Text += 1
            lblMsg.Text = "Incorrect captcha :'("
        Else
            If txtuser.Text = "harry" And txtpassword.Text = "potter" Then
                lblMsg.Text = "You are logged in ok!"
                txtbadlogins.Text = 0
            
            Else
                txtbadlogins.Text += 1
                lblMsg.Text = "User or password incorrect"
            End If
        End If
        
        ActivateCaptchaIfBadLogins()
        ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "CaptchaReload", "reloadRecaptcha()", True)
        UpdatePanelLogin.Update()
        
    End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>

        <script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            function reloadRecaptcha() {
                
                Recaptcha._init_options(RecaptchaOptions);
                if (RecaptchaOptions && 'custom' == RecaptchaOptions.theme) {
                    if (RecaptchaOptions.custom_theme_widget) {
                        Recaptcha.widget = Recaptcha.$(RecaptchaOptions.custom_theme_widget);
                        Recaptcha.challenge_callback();
                         
                    }
                } else {
                    if (Recaptcha.widget == null || !document.getElementById('recaptcha_widget_div')) {
                        $('#cbCaptcha').show().html('<div id="recaptcha_widget_div" style="display:none"></div>');
                        Recaptcha.widget = Recaptcha.$('recaptcha_widget_div');
                         
                    }
                    Recaptcha.reload();
                    Recaptcha.challenge_callback();
                     
                }
                 
            }
</script>
    <form id="form1" runat="server">
    

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanelLogin" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                Message:<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label><br/>
        Bad logins counter <asp:TextBox ID="txtbadlogins" runat="server" Width="33px">0</asp:TextBox>
        <br/><br/><br/><br/>
        Username <asp:TextBox ID="txtuser" runat="server">harry</asp:TextBox><br/>
        Password <asp:TextBox ID="txtpassword" runat="server" TextMode="Password">potter</asp:TextBox><br/>
        <div id="divRecaptcha" runat="server" visible="false">
            <div id="cbCaptcha" style="display: none;">
                <!-- for callback recaptcha reload -->
            </div>
            <recaptcha:RecaptchaControl ID="recaptcha" theme="white" runat="server" PublicKey="6LdBuOgSAAAAANbjWrJDRfh-meOLszgtPN3dA14n"
                PrivateKey="6LdBuOgSAAAAAJUHgY32k6xXTC9Cr3d3_MG18LY2" />
        </div>
                <asp:Button ID="btnLogin" runat="server" Text="Login" 
                    onclick="btnLogin_Click" />
            </ContentTemplate>
        </asp:UpdatePanel>
    
    </form>
</body>
</html>

Open in new window

example-website-recaptcha.zip
0
Comment
Question by:Sherman Guti
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 

Author Comment

by:Sherman Guti
ID: 39603419
any help?
0
 

Accepted Solution

by:
Sherman Guti earned 0 total points
ID: 39603455
I got the solution!!


https://developers.google.com/recaptcha/docs/display#Standard


Fuck off experts-exchange
you realy sucks, no one write nothing in 30hs of posted this
I will cancel the suscription INMEDIATLYYYYYYYY
0
 

Author Closing Comment

by:Sherman Guti
ID: 39603457
No one help me in 30 hours of posted my problem

I will cancel the suscription inmediatly

you sucks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question