Asp.Net NoCaptcha not updating in UpdatePanel -
nocaptcha image works fine if don't add updatepanel, if add updatepanel not update on postback. here code :
<asp:updatepanel id="updatepaneltriggers" runat="server" updatemode="conditional"> <contenttemplate> --nocaptcha <div id="captcha" runat="server" class="login_re_captcha_hidden"> <div class="g-recaptcha" data-sitekey="key"> </div> </div> </contenttemplate> <triggers> <asp:asyncpostbacktrigger controlid="btnlogin" /> </triggers> </asp:updatepanel> <asp:updateprogress id="uprcampaigns" runat="server" displayafter="0" associatedupdatepanelid="updatepaneltriggers"> <progresstemplate> <div class="loadingiconbackground"> <div style="height: 85px; top: 0px; width: 100%"> </div> <div style="min-height: 100%; background-color: white"> </div> </div> <div class="loadingicondiv"> <img src="images/pleasewait_small.gif" /> </div> </progresstemplate> </asp:updateprogress>
here server side code. use code validate user's answer :
private bool validateuserrecaptcharesponse() { bool validated = true; if (request["g-recaptcha-response"] != null && request["g-recaptcha-response"] != "") { string scatcharesponse = request["g-recaptcha-response"]; string ssecret = "key"; //put in webconfig string sipaddress = request.servervariables["remote_addr"].tostring(); sipaddress = "x.2x.x.18"; // next create webclient instance call web api , result... system.net.webclient wc = new system.net.webclient(); string srequest = string.format("https://www.google.com/recaptcha/api/siteverify?secret={0}&response={1}&remoteip={2}", ssecret, scatcharesponse, sipaddress); string sresponse = wc.downloadstring(srequest); //add <system.net> //<defaultproxy usedefaultcredentials="true" /> //</system.net> downloadstring(srequest) in webconfig // result comes json object. i've created simple googleresponse object hold information // , using javascriptserializer deserialize response accordingly... system.web.script.serialization.javascriptserializer serializer = new system.web.script.serialization.javascriptserializer(); googleresponse response = serializer.deserialize<googleresponse>(sresponse); // can check if call succeeded or failed , take necessary action if (!response.success) { // output error on front end here validated = false; } } else { // ok if you're here, didn't check bot question on form. // tell user , resubmit form validated = false; } return validated; }
please ?
i assume mean it's not working in postback when click btnlogin right? because that's trigger defined. maybe try setting eventname.
it should @ least work when this:
updatemode="always".
update: think understand happens. if correct have included javascript file calls render method defaults unload. if correct updatepanel updates , still needs call:
grecaptcha.render();
or specify arguments. can see whether mandatory or not. default should first tag finds , use attributes set, wouldn't expect parameters mandatory. see documentation https://developers.google.com/recaptcha/docs/display#render_param
either disable calling render/onload on initial load, can do:
$(function() { grecaptcha.render(); }
or add mechanism call client side code updates updatepanel. explanation can found on https://msdn.microsoft.com/en-us/library/bb398976(v=vs.140).aspx
an example should work (but typing head on macbook, can't verify/test it) adding markup of page:
<script type="text/javascript"> function partialpostbackfinished(sender, args) { //do whatever needs triggered, esp when want applied on panels_updated avoid registering events multiple times grecaptcha.render() } if (sys != undefined) { //there's scriptmanager on page var prm = sys.webforms.pagerequestmanager.getinstance(); prm.add_endrequest(partialpostbackfinished); } </script>
Comments
Post a Comment