ASP.NET CAPTCHA Form Object Settings VB.NET Code Example

The ASP.NET SimpleCaptcha form object settings example project shows how to configure BotDetect CAPTCHA challenges by setting SimpleCaptcha control properties in ASP.NET form source.

First Time Here?

Check the BotDetect Developer Crash Course for key integration steps.

Multiple ASP.NET forms within the same ASP.NET website can be protected by BotDetect SimpleCaptcha challenges: e.g. you could add SimpleCaptcha controls in both your Contact form and Registration form source.

To function properly, separate SimpleCaptcha challenges placed on each form should have different names (CaptchaStyleName values, Captcha1 and Captcha2 in this example), and can use completely different SimpleCaptcha settings.

Even multiple SimpleCaptcha instances placed on the same form won't interfere with each other's validation and functionality. And if a user opens the same page in multiple browser tabs, each tab will independently validate the shown Captcha code.

Shared SimpleCaptcha settings should always be placed in the web.config application configuration file, and only diverging settings set through SimpleCaptcha object instance properties in form code, to avoid code duplication.

Settings that affect only SimpleCaptcha container markup generation take effect immediately (changing SimpleCaptcha.Html output), but settings that affect SimpleCaptcha challenge (image or sound) generation in separate Http requests need to be saved in ASP.NET Session state when set through SimpleCaptcha object instance properties in form source, consuming server resources and reverting to defaults when the ASP.NET Session expires.

Please note that if configured values are dynamic (e.g. CaptchaRandomization helper or other function calls in form code), they will be re-calculated only when the form is reloaded (form code is executed). For example, SimpleCaptcha ImageStyle randomized in ASP.NET form source will not change on each SimpleCaptcha Reload button click, but only on each form load.

Download the BotDetect ASP.NET CAPTCHA Component and run this example
  • C#
  • VB.NET

Visual Studio 2005-2017 / .NET 2.0 and onwards

By default, the VB.NET version of the ASP.NET SimpleCaptcha form object settings example project is installed at:
C:\Program Files\Captcha Inc\BotDetect 4 CAPTCHA Component\Asp.Net\.NET\WebApp\SimpleAPI\CaptchaFormObjectSettingsExample\VBNet

You can also run it from the BotDetect Start Menu:
Programs > Captcha Inc > BotDetect 4 CAPTCHA Component > ASP.NET > ASP.NET Examples > Run .NET Examples


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" 
Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="">
<head id="Head1" runat="server">
  <title>BotDetect ASP.NET CAPTCHA Options: Form Object Settings Code Example</title>

  <form runat="server" class="column" id="form1">
    <h1>BotDetect ASP.NET CAPTCHA Options:
      <br />
      Form Object Settings Code Example</h1>
      <legend>ASP.NET WebForm CAPTCHA Validation</legend>
      <p class="prompt">
        <label for="Captcha1CodeTextBox">Retype the characters from the picture:</label></p>
      <BotDetect:WebFormsSimpleCaptcha runat="server" ID="Captcha1"/>
      <div class="validationDiv">
        <asp:TextBox ID="Captcha1CodeTextBox" runat="server"></asp:TextBox>
        <asp:Label ID="Captcha1CorrectLabel" runat="server" CssClass="correct" 
        Text="Correct!" Visible="false"></asp:Label>
        <asp:Label ID="Captcha1IncorrectLabel" runat="server" 
        CssClass="incorrect" Text="Incorrect!" Visible="false"></asp:Label>

      <legend>ASP.NET WebForm CAPTCHA Validation</legend>
      <p class="prompt">
        <label for="Captcha2CodeTextBox">Retype the characters from the picture:</label></p>
      <BotDetect:WebFormsSimpleCaptcha runat="server" ID="Captcha2"/>
      <div class="validationDiv">
        <asp:TextBox ID="Captcha2CodeTextBox" runat="server"></asp:TextBox>
        <asp:Label ID="Captcha2CorrectLabel" runat="server" CssClass="correct" 
        Text="Correct!" Visible="false"></asp:Label>
        <asp:Label ID="Captcha2IncorrectLabel" runat="server" 
        CssClass="incorrect" Text="Incorrect!" Visible="false"></asp:Label>

    <asp:Button ID="SubmitFormButton" runat="server" Text="Submit Form" />


Imports BotDetect

Partial Class _Default
  Inherits System.Web.UI.Page
  Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As  _
  System.EventArgs) Handles Me.PreRender

    ' Form validation
    If (IsPostBack) Then

      Dim isHuman1 As Boolean = Captcha1.Validate()
      If (isHuman1) Then

        Captcha1CorrectLabel.Visible = True
        Captcha1IncorrectLabel.Visible = False


        Captcha1CorrectLabel.Visible = False
        Captcha1IncorrectLabel.Visible = True
      End If

      Dim isHuman2 As Boolean = Captcha2.Validate()
      If (isHuman2) Then

        Captcha2CorrectLabel.Visible = True
        Captcha2IncorrectLabel.Visible = False


        Captcha2CorrectLabel.Visible = False
        Captcha2IncorrectLabel.Visible = True

      End If
    End If
  End Sub
End Class


<?xml version="1.0"?>
  For more information on how to configure your ASP.NET application, please 
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
      <!-- Register the HttpHandler used for BotDetect Simple API requests -->
      <add verb="GET" path="BotDetectCaptcha.ashx" 
      type="BotDetect.Web.SimpleCaptchaHandler, BotDetect"/>
    <pages controlRenderingCompatibilityVersion="4.5">
      <!-- Register the BotDetect tag prefix for easier use in all pages -->
      <add assembly="BotDetect" namespace="BotDetect.Web.UI" 
    <compilation debug="false" targetFramework="4.5"/>
    <httpRuntime requestValidationMode="4.5" targetFramework="4.5" 
    encoderType="System.Web.Security.AntiXss.AntiXssEncoder, System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    <machineKey compatibilityMode="Framework45"/>
    <validation validateIntegratedModeConfiguration="false"/>
      <!-- Register the HttpHandler used for BotDetect Simple API requests (IIS 7.0+) -->
      <remove name="BotDetectCaptchaHandler"/>
      <add name="BotDetectCaptchaHandler" preCondition="integratedMode" verb="GET" 
      path="BotDetectCaptcha.ashx" type="BotDetect.Web.SimpleCaptchaHandler, BotDetect"/>


<?xml version="1.0" encoding="UTF-8"?>
<botdetect xmlns="" 



In botdetect.xml, we configure captcha options for the ExampleCaptcha captcha style name. You can find a full list of available Captcha configuration options and related instructions at the Captcha configuration options page .

Current BotDetect Versions