views:

328

answers:

1

I am trying to use the following A CAPTCHA Server Control for ASP.NET - by Jeff Atwood within an ASP.NET MVC site. The custom control doesn't seem to be validating when the form is submitted.

Is there anyone who has done any work with this sample using ASP.NET MVC?

The basic code I am using is as follows:

<% using (Html.BeginForm()) { %>
<CaptchaControl:CaptchaControl ID="CaptchaControl" Name="Security" runat="server"></CaptchaControl:CaptchaControl>
<input type="submit" value="Send Message" />
<% } %>
+1  A: 

It's not really recommended to use ASP.Net server controls for an ASP.Net MVC site. ASP.Net MVC does not execute the page lifecycle like regular ASP.Net does. The server controls may render, but if they rely on ViewState or Postback events, they will not work.

Looking at the code for the Captcha Control, this seems to be the problem. The validation is programmed to occur during LoadPostBackData. Unfortunately, there is no concept of a postback in ASP.Net MVC... and hence no postback data.

womp