Captcha

This control is based on the work by Jeff Atwood in this CodePlex article: http://www.codeproject.com/aspnet/CaptchaControl.asp

Because the Captcha Control includes an image, it's not enough to simply drop the control on a WebForm. You need to modify Web.config to map requests for the Captcha HTTP Handler which is responsible for rendering the image.

In web.config, add the following to the httpHandlers section.

<configuration>
  ...
  <system.web>
    ...
    <httpHandlers>
      ...
      <add verb="*" path="*CaptchaImage.ashx" type="Subkismet.Captcha.CaptchaImageHandler, Subkismet"/>
    </httpHandlers>
  </system.web>
</configuration>

Sample Usage (Demo)

<script runat="server" language="C#">
  protected void OnVisibleCaptchaButtonClick(object sender, EventArgs e)
  {
    if(Page.IsValid)
    {
      visibleSuccessLiteral.Visible = true;
    }
  }

</script>
<p class="success">
  <asp:Literal ID="visibleSuccessLiteral" 
    runat="server" 
    Text="Valid!"
    EnableViewState="false"
    Visible="false" />
</p>
<div class="captcha">
  <sbk:CaptchaControl id="captcha" 
    runat="server" 
    ErrorMessage="Oops! You must be bad at reading." 
    Display="dynamic"
    CaptchaLength="4"
    ValidationGroup="Visible" />
</div>

<div>
  <asp:Button ID="visibleButton" runat="server" 
    Text="Submit" 
    OnClick="OnVisibleCaptchaButtonClick" 
    ValidationGroup="Visible" />
</div>

Last edited Jun 13, 2007 at 3:45 AM by Haacked, version 8

Comments

No comments yet.