noCAPTCHA reCAPTCHA在UpdatePanel中消失 [英] noCAPTCHA reCAPTCHA disappearing in UpdatePanel

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

问题描述

我正在使用VB.Net将noCAPTCHA reCAPTCHA实现为现有形式.它位于UpdatePanel中,并使用服务器端验证来验证用户是否已完成验证码(请参阅

I'm implementing noCAPTCHA reCAPTCHA into an existing form with VB.Net. It is located within an UpdatePanel and uses server side validation to verify the user has completed the CAPTCHA (See Validating Recaptcha 2 (No CAPTCHA reCAPTCHA) in ASP.NET's server side)

如果用户无法输入CAPTCHA或任何其他有效字段,则由于回发,CAPTCHA无法重新加载.如何解决此问题并使其正确以使CAPTCHA在回发后不会消失?

If a user fails to the CAPTCHA or any other of the validated fields, the CAPTCHA fails to reload due to postback. How do resolve this and make it so that the CAPTCHA does not disappear after a postback?

我的验证码:

<div id="captcha" class="g-recaptcha" runat="server" data-sitekey="MySiteKey"></div>

api.js放置在Site.Master标头中.

The api.js is placed in the Site.Master header.

<script src="https://www.google.com/recaptcha/api.js" async defer></script>

展开.

我尝试了一些解决方法,但最终失败了.我加了

I have tried a work around but ultimately failed. I added

<div id="captcha" class="g-recaptcha" runat="server" data-sitekey="MySiteKey"></div>

放到我的MasterPage正文中,然后将其扔到UpdatePanel中,给它一个ID,以此类推.

to the body of my MasterPage and threw it in an UpdatePanel, gave it an id, etc.

    <asp:UpdatePanel UpdateMode="Conditional" runat="server" ID="noCaptcha">
        <ContentTemplate>
            <asp:ScriptManager runat="server"></asp:ScriptManager>
            <script src="https://www.google.com/recaptcha/api.js" async defer></script>
        </ContentTemplate>
    </asp:UpdatePanel>

然后,我在Site Master的代码背后创建了一个函数,如下所示:

I then created a function in the code-behind of the Site Master as follows:

Public Sub TriggerCaptchaReload()
    noCaptcha.Update()
End Sub

当用户尝试验证并提交表单

When the user tried to verify and submit the form

如果他们失败了,我试图使更新面板刷新为

If they failed I attempted to cause the update panel to refresh with

CType(Me.Page.Master, MasterPage).TriggerCaptchaReload()

位于后面的控制代码上.

which is located on the control code behind.

这不起作用.也许可以找到一个潜在的解决方案?

This didn't work. Maybe there is a potential solution to find with that?

推荐答案

为解决此问题,我执行了以下操作:

To solve this issue I did the following:

我的验证码更改为以下div:

My CAPTCHA code changed to the following div:

<div id="recaptcha" class="recaptcha"></div>

然后我通过将api链接更改为以下内容并将其放置在上方的div下方,来在reCAPTCHA上实现显式呈现.

I then proceeded to implement explicit rendering on the reCAPTCHA by changing the api link to the following and placing it below the div above.

<script src="https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit"
            async defer>
            </script>

在我包含的标题中

<script type="text/javascript">
    var onloadCallback = function () {
        grecaptcha.render('recaptcha', {
            'sitekey': 'MySiteKey'
        });
    };
</script>

在验证码失败后的代码中,我用

In the code behind if the CAPTCHA fails I reload the CAPTCHA with

ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "loadCaptcha", "grecaptcha.render('recaptcha', {'sitekey': 'MySiteKey' });", True)

这篇关于noCAPTCHA reCAPTCHA在UpdatePanel中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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