asp.net - noCAPTCHA reCAPTCHA disappearing in UpdatePanel -


i'm implementing nocaptcha recaptcha existing form vb.net. located within updatepanel , uses server side validation verify user has completed captcha (see validating recaptcha 2 (no captcha recaptcha) in asp.net's server side)

if user fails captcha or other of validated fields, captcha fails reload due postback. how resolve , make captcha not disappear after postback?

my captcha code:

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

the api.js placed in site.master header.

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

to expand.

i have tried work around failed. added

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

to body of masterpage , threw in updatepanel, gave 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> 

i created function in code-behind of site master follows:

public sub triggercaptchareload()     nocaptcha.update() end sub 

when user tried verify , submit form

if failed attempted cause update panel refresh

ctype(me.page.master, masterpage).triggercaptchareload() 

which located on control code behind.

this didn't work. maybe there potential solution find that?

to solve issue did following:

my captcha code changed following div:

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

i proceeded implement explicit rendering on recaptcha changing api link following , placing below div above.

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

in header of included

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

in code behind if captcha fails reload captcha

scriptmanager.registerstartupscript(updatepanel1, updatepanel1.gettype(), "loadcaptcha", "grecaptcha.render('recaptcha', {'sitekey': 'mysitekey' });", true) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -