Recaptcha in Ajax Contenthttp://forums.asp.net/t/1787062.aspx/1?Recaptcha+in+Ajax+ContentSat, 31 Mar 2012 20:52:52 -040017870624907352http://forums.asp.net/p/1787062/4907352.aspx/1?Recaptcha+in+Ajax+ContentRecaptcha in Ajax Content <p>Not sure if it would be considered a bug, but I thought I would mention that the</p> <pre class="prettyprint">@ReCaptcha.GetHtml()</pre> <p>&nbsp;helper method doesn't work in content loaded via ajax.</p> <p>To get around this:</p> <p>Simply do not use the Razor @Recaptcha helper. Instead embed the code below in the content you are loading via ajax.</p> <pre class="prettyprint">&lt;div id="myCaptcha"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; Recaptcha.destroy(); Recaptcha.create("Pub_key", "myCaptcha", { theme: "clean" }); &lt;/script&gt;</pre> <p>This way the script gets ran when the ajax content is loaded and everything should work. The rest of the implementation in the layout (Recaptcha api javascript reference), controller (check validation), etc remains the same.</p> <p><br> Thought I would mention it and see if ajax could some how be taken care of as well.</p> 2012-03-30T02:15:27-04:004909137http://forums.asp.net/p/1787062/4909137.aspx/1?Re+Recaptcha+in+Ajax+ContentRe: Recaptcha in Ajax Content <p>Can you elaborate more on your work around?&nbsp; I just bumped into this a few hours ago and I'm not sure I follow all of your work around.</p> 2012-03-31T02:33:05-04:004909149http://forums.asp.net/p/1787062/4909149.aspx/1?Re+Recaptcha+in+Ajax+ContentRe: Recaptcha in Ajax Content <p>I updated the work around a little, if you still have questions let me know which part you need help with and I'll do my best to explain it.</p> 2012-03-31T03:20:36-04:004909957http://forums.asp.net/p/1787062/4909957.aspx/1?Re+Recaptcha+in+Ajax+ContentRe: Recaptcha in Ajax Content <p>Thanks for the update.&nbsp; The work around didn't function for me originally because I was also loading the recaptch js inside the jquery dialog box.&nbsp; Which created a race condition between loading the js source and executing it.&nbsp; I fixed it with jquery getScript:</p> <pre class="prettyprint">&lt;div id=&quot;captchadiv&quot;&gt;&lt;/div&gt; &lt;script type=&quot;text/javascript&quot;&gt; $.getScript(&quot;http://www.google.com/recaptcha/api/js/recaptcha_ajax.js&quot;, function () { Recaptcha.create(&quot;6Lf8oc8SAAAAACgdybPC2Mx2eX0CUFDCBSwXCYQw&quot;, 'captchadiv', { tabindex: 1, theme: &quot;red&quot;, callback: Recaptcha.focus_response_field }); });</pre> <p></p> <p>In case that helps anyone else.</p> <p></p> <p>Thanks for your reply Victoryismine.</p> 2012-03-31T20:52:52-04:00