回传过程中Updatepanel中的Recaptcha消失了 [英] Recaptcha in Updatepanel disappears during PostBack

查看:102
本文介绍了回传过程中Updatepanel中的Recaptcha消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google ReCaptcha V2,它在更新面板中.如果验证失败,则ReCaptcha在回发时消失. 我读过类似的主题,但尚未找到解决我问题的答案.

I am using Google ReCaptcha V2 and it is inside an updatepanel. IF validation failed ReCaptcha disappears on postback. I read similar topics but I have not yet found an answer that solves my problem.

请帮助!

我的ASPX代码:

<%@ Register Assembly="GoogleReCaptcha" Namespace="GoogleReCaptcha" TagPrefix="cc1" %>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 <form id="formRegister" runat="server">
    <asp:ScriptManager ID="ScriptManagerRegister" EnablePartialRendering="true" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanelRegister" hildrenAsTriggers="false" UpdateMode="Conditional" runat="server">
        <ContentTemplate>

               <asp:Panel ID="Panel1" runat="server"></asp:Panel>
               <asp:Button ID="ButtonRegister" runat="server" Text="Registrera" CssClass="btn btn-primary btn-md" /><br />
               <asp:Label ID="Label1" runat="server" Text=""></asp:Label>

            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
 </form>
</asp:Content>

我在C#后面的代码

GoogleReCaptcha.GoogleReCaptcha ctrlGoogleReCaptcha = new GoogleReCaptcha.GoogleReCaptcha();

    protected override void CreateChildControls()
    {
        base.CreateChildControls();
        ctrlGoogleReCaptcha.PublicKey = "My Public Key";
        ctrlGoogleReCaptcha.PrivateKey = "My Private Key";
        this.Panel1.Controls.Add(ctrlGoogleReCaptcha);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ButtonRegister.Click += new EventHandler(ButtonRegister_Click);
    }

    protected void ButtonRegister_Click(object sender, EventArgs e)
    {
        if (ctrlGoogleReCaptcha.Validate())
        {
            //submit form
            Label1.Text = "Success";
        }
        else
        {
            Label1.Text = "Captcha Failed!! Please try again!!";
        }
    }

推荐答案

在正文后使用此脚本

<body>
<script language="javascript" type="text/javascript"> 
    function pageLoad() 
    { 

        $('.g-recaptcha').each(function (index, obj) {
            grecaptcha.render(obj, { 'sitekey': 'yoursitekey' });
        });
    } 
</script>

这篇关于回传过程中Updatepanel中的Recaptcha消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆