BotDetect ASP.NET CAPTCHA Client-Side API Reference

BotDetect ASP.NET Captcha client-side functionality is encapsulated in the BotDetectScripts.js JavaScript include. BotDetect Captcha controls automatically use this library and construct the necessary objects.

BotDetect Client-Side Prototype Reference

The main client-side BotDetect prototype (accessible on the whole page using BotDetect.<member_name>) exposes several global functions and constants.

BotDetect Client-Side Prototype Reference
BotDetect client-side prototype public function Init
  • captchaId
  • inputId
  • autoFocusInput
  • autoClearInput
  • autoLowercaseInput
  • autoReloadExpiredImage
  • autoReloadPeriod
  • autoReloadTimeout

The client-side BotDetect initialization function (used as a "constructor") takes the following arguments:

  • captchaId is the unique Captcha identifier of the Captcha control on the page. It's a mandatory parameter for all Captcha scripts to run
  • inputId is the client-side identifier of the Captcha code user input field. It's needed for all scripts that process the user input
  • autoFocusInput is a boolean value specifying if the user input should be automatically focused on Captcha Reload and Sound button clicks
  • autoClearInput is a boolean value specifying if the user input should be automatically cleared on Captcha Reload button clicks
  • autoLowercaseInput is a boolean value specifying if the user input should be automatically lowercased during typing
  • autoReloadExpiredImage is a boolean value specifying if Captcha images displaying expired Captcha codes should be automatically reloaded
  • autoReloadPeriod is the millisecond count equivalent of the Captcha code timeout value
  • autoReloadTimeout is the upper bound millisecond count, after which automatic reloading will stop. This is used to save resources and stop generating Captchas if the user leaves the form open during the weekend and leaves town, for example
BotDetect client-side prototype public function RegisterCustomHandler
  • eventName
  • userHandler

This function is used to register a user-defined handler function, which will be called by BotDetect any time the specified BotDetect event occurs.

The first parameter is the name of the BotDetect event you want to handler, and the second is the (parameter-less) handler function that should be called

BotDetect client-side prototype constant value ReloadTimerDelay = 250 The delay between each Captcha Reload animation "tick" (status update), in milliseconds.
BotDetect client-side prototype constant value ReloadTimerMaxTicks = 100 The maximum number of "ticks" the Captcha Reload animation will go through before it stops (in case the Captcha image reloading Http request timeouts or fails to return a new image).
BotDetect client-side prototype constant value AjaxTimeout = 10000 The maximum time (in milliseconds) spent waiting for server responses to asynchronous Http requests. After this period, an Ajax error is raised

BotDetect Client-Side Object Reference

BotDetect client-side object instances (accessible within member functions using this.<member_name>, or on the page using <captchaId>.<member_name>) expose all Captcha workflow functions and values, as well as several Captcha life-cycle events.

BotDetect Client-Side Object Reference
BotDetect client-side object public function PlaySound Starts Captcha sound playback for the current Captcha client-side instance
BotDetect client-side object public function ReloadImage Reloads the current Captcha client-side instance Captcha image
BotDetect client-side object public function Validate Starts Ajax validation of the user input for the current Captcha client-side instance
BotDetect client-side value FollowHelpLink Will the click on the Captcha help link open the configured Captcha help page
BotDetect client-side value Image The <img> element containing the Captcha image
BotDetect client-side value InputElement The Captcha code user input field (usually a <input type="text" ... /> element). Only set if the user input client-side ID was specified in the constructor
BotDetect client-side value SoundPlaceholder The invisible <div> element used as a container for sound objects created during Captcha sound playback
BotDetect client-side value ProgressIndicator The text element created during Captcha image reloading, and used as a Reload progress indicator
BotDetect client-side value SoundUrl BotDetect Captcha Sound Url, used during sound playback
BotDetect client-side value ValidationUrl BotDetect Captcha Ajax validation Url, used during Ajax Captcha validation calls
BotDetect client-side value ValidationResult Set during Ajax Captcha validation
BotDetect client-side value AutoReloading Flag indicating that the Captcha image is currently being reloaded because the automatic reloading timer has activated
BotDetect client-side custom event PostInit This event occurs after the BotDetect client-side object has been successfully initialized
BotDetect client-side custom event PreReloadImage

This event occurs after the user clicks the Captcha Reload button, but before image reloading starts.

The default handler clears previous user input, and focuses the Captcha code input field (if auto-clearing and auto-focusing are enabled)

BotDetect client-side custom event PostReloadImage

This event occurs after the Captcha image has been successfully reloaded.

The default handler updates the Captcha sound Url, and sets up automatic image reloading (if auto-reloading is enabled and we haven't reached the timeout threshold)

BotDetect client-side custom event PrePlaySound

This event occurs after the user clicks the Captcha Sound button, but before sound playing starts.

Note that there is no matching PostPlaySound event, since the available client-side sound playback options don't notify calling functions when playback ends

BotDetect client-side custom event OnHelpLinkClick

This event occurs when the user clicks the Captcha help link. Captcha help page opening can be aborted in this handler by setting the BotDetect client-side object's FollowHelpLink property to false

BotDetect client-side custom event PreAjaxValidate This event occurs after the BotDetect client-side Validate() function is called, but before any Ajax calls are made
BotDetect client-side custom event AjaxValidationFailed

This event occurs after BotDetect Ajax Captcha validation returns false.

The default handler reloads the Captcha image, since Captcha validation has invalidated the currently displayed Captcha code on the server

BotDetect client-side custom event AjaxValidationPassed This event occurs after BotDetect Ajax Captcha validation returns true
BotDetect client-side custom event AjaxValidationError

This event occurs if BotDetect Ajax Captcha validation throws errors or timeouts.

The default handler aborts any Ajax operations left, and sets the AjaxError flag, which in turn temporarily sets the validation result to true to enable full page postback