Posted: 6/21/2011
I have a recaptcha page that has a recaptchacontrol, a submit button, and a label nested in a Master page. When I click the submit button everything is fine. When I place the cursor in the recaptcha control regardless if I enter the correct text, if I hit enter it redirects to Default.aspx. I haven't done a redirect I cannot figure out why. I even tried putting an invisible fakebutton in my master page and setting it as the defaultbutton but that didn't work. Here's my code, and code behind.
<%@ Page Title="" Language="C#" MasterPageFile="~/Default.Master" AutoEventWireup="true" CodeBehind="CaptchaPage.aspx.cs" Inherits="TheCouponBot.com.CaptchaPage" %> <%@ Register TagPrefix="recaptcha" Namespace="Recaptcha" Assembly="Recaptcha" %> <asp:Content ID="Content1" ContentPlaceHolderID="CpMain" runat="server"> <table align="center" cellpadding="0" cellspacing="0" style="width: 800px; height: 568px; margin-bottom: 0px"> <tr> <td align="center" class="style5"> <img alt="SpamProtection" src="Images/SpamProtection.jpeg" style="width: 350px; height: 200px" /></td> </tr> <tr> <td align="center" class="style2" style="height: 173px"> <recaptcha:RecaptchaControl ID="recap" PublicKey="6LfESMUSAAAAADa_u5RwSbuDp461qJJ4HZbZ4-Pc" PrivateKey="6LfESMUSAAAAAJZTiyCoGmRfHiXkDdgErDRCTuDN" runat="server" Theme="blackglass" CustomThemeWidget="recaptcha_widget" /> </td> </tr> <tr> <td align="center" class="style2"> <asp:Button ID="CapSubmit" runat="server" Text="Submit" onclick="CapSubmit_Click1" /> </td> </tr> <tr> <td align="center"> <asp:Label ID="Label1" runat="server"></asp:Label> <br /> </td> </tr> </table> </asp:Content>
Code behind:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace TheCouponBot.com { public partial class CaptchaPage : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void CapSubmit_Click1(object sender, EventArgs e) { if (Page.IsValid == true) { Response.Redirect("~/JoinNow.aspx"); } else { Label1.Text = "That was incorrect. Please try again."; } } } }
Posted: 7/5/2011
I fugured this one out after a lot of pulling my hair out.
I just placed my recaptcha control and submit button inside an asp panel and set the defaultbutton="Capsubmit"
<asp:Panel ID="RecapPanel" DefaultButton="CapSubmit" runat="server"> <recaptcha:RecaptchaControl ID="recap" PublicKey="6LfESMUSAAAAADa_u5RwSbuDp461qJJ4HZbZ4-Pc" PrivateKey="6LfESMUSAAAAAJZTiyCoGmRfHiXkDdgErDRCTuDN" runat="server" Theme="blackglass" CustomThemeWidget="recaptcha_widget" /> </td> </tr> <tr> <td align="center" class="style2"> <asp:Button ID="CapSubmit" runat="server" Text="Submit" onclick="CapSubmit_Click1" /> </asp:Panel>
Mike, please don't mark your own answers 'as answered'. Do that when someone elses reply to your thread post if it's helpful and resolved your issue. If you have code snippets or some solution to a common problems and want to share it with everyone, my advice is to write a blog post about it.
Thanks,Hajan