webforms - Google reCAPTCHA 2 ("noCAPTCHA") does not get reapplied when using ASP.NET Web-Form UpdatePanel -
google recaptcha 2 ("nocaptcha") not reapplied when using updatepanel
i not using old asp.net recaptcha control.
here code running.
<asp:scriptmanager id="scriptmanager1" runat="server" /> <asp:updatepanel id="googlecaptchaupdatepanel" runat="server" updatemode="always" > <contenttemplate> <div class="googlecaptchawrapper"> <div class="g-recaptcha" data-sitekey="<%= getcaptchapublickey() %>"></div> <asp:label id="captchaerror" cssclass="captchaerror" runat="server" forecolor="red" visible="false" /> </div> <div class="smallcontentrow" style="margin-top: 10px; margin-left: auto; margin-right: auto; width: 100%; text-align: center;"> <asp:linkbutton id="btnsubmit" runat="server" cssclass="mybtn" causesvalidation="false" text="submit" tabindex="9" tooltip="click submit info"/> <asp:linkbutton id="btncancel" runat="server" causesvalidation="false" cssclass="mybtn" text="cancel" tabindex="10" tooltip="click cancel info "/> </div> </contenttemplate> </asp:updatepanel>
when click submit button, captcha not re-applied screen.
i've attempted resolve issue various javascript solutions have been posted, seem older version of google's recaptcha.
i figured out how.
i ended explicitly rendering new recaptcha, or recaptcha 2.
in site masterpage, declared recaptcha js scripts as:
<script src="https://www.google.com/recaptcha/api.js?onload=onloadcallback&render=explicit" async defer ></script>
in webpage, created placeholder captcha this:
<div class="mycaptchawrapper"> <div id="mycaptcha" class="g-recaptcha"></div> <asp:label id="errormessage" cssclass="stylederrors" runat="server" forecolor="red" visible="false" /> </div>
then, in captcha js:
function loadcaptcha() { grecaptcha.render('mycaptcha', { 'sitekey': mysitekey, 'theme': 'clear', 'callback': myclientresponsecallback }); }
and call secure web service in myclientresponsecallback server-side processing need to.
doing this, can handle action when user clicks on 'apply' in recaptcha, , can handle checking if captcha has been answered through server-side processing in asp.net post-back.
Comments
Post a Comment