ASPxCaptcha Class
A control used for the challenge-response authentication.
Namespace: DevExpress.Web
Assembly: DevExpress.Web.v24.1.dll
NuGet Package: DevExpress.Web
Declaration
Remarks
The ASPxCaptcha class implements the functionality of a challenge-response authentication test, which enables verifying that submitted data came from a human, and not a robot or script.
Create a Captcha Control
Design Time
The ASPxCaptcha control is available on the DX.24.1: Common Controls toolbox tab in the Microsoft Visual Studio IDE.
Drag the control onto a form and customize the control’s settings, or paste the control’s markup in the page’s source code.
<dx:ASPxCaptcha ID="Captcha" runat="server" ClientInstanceName="ClientCaptcha">
<TextBox Position="Bottom" />
<ValidationSettings SetFocusOnError="true" ErrorDisplayMode="ImageWithText" />
</dx:ASPxCaptcha>
Run Time
using DevExpress.Web;
...
protected void Page_Load(object sender, EventArgs e)
{
ASPxCaptcha captcha = new ASPxCaptcha();
captcha.ID = "Captcha";
Page.Form.Controls.Add(captcha);
captcha.ClientInstanceName = "ClientCaptcha";
captcha.TextBox.Position = DevExpress.Web.Captcha.ControlPosition.Bottom;
captcha.ValidationSettings.SetFocusOnError = true;
captcha.ValidationSettings.ErrorDisplayMode = ErrorDisplayMode.ImageWithText;
}
Note
DevExpress controls require that you register special modules, handlers, and options in the Web.config file. You can change this file or switch to the Design tab in the Microsoft Visual Studio IDE to automatically update the Web.config file. Note that this information is automatically registered if you use the DevExpress Template Gallery to create a project.
The ASPxCaptcha control uses a session state to store a verification code. Therefore, the session state mode attribute should not be Off for the control to operate properly.
The control consists of the following elements:
- Challenge image is an automatically generated image representation of a random text. The image settings can be customized using the ASPxCaptcha.ChallengeImage property. To define a set of characters from which a random text should be generated, use the control’s ASPxCaptcha.CharacterSet property. You can control the number of characters to be displayed within the challenge image by using the ASPxCaptcha.CodeLength property. If you want to render a custom challenge image, you can handle the ASPxCaptcha.ChallengeImageCustomRender event.
- The Refresh button allows changing the code displayed within the challenge image. To control the refresh button’s content and appearance, use the ASPxCaptcha.RefreshButton and ASPxCaptcha.RefreshButtonStyle properties.
- The Text box allows end-users to input text recognized from the challenge image. To customize the content and layout of the text box element, use the ASPxCaptcha.TextBox property. The element’s appearance can be defined using properties available via the ASPxCaptcha.TextBoxStyle property. The text box element also has a built-in validation mechanism whose behavior can be customized using the settings accessed via the ASPxCaptcha.ValidationSettings property. The availability of the built-in validation is controlled by the CaptchaValidationSettings.EnableValidation property.
- The Loading panel is displayed when the challenge image’s code is refreshed. Use the ASPxCaptcha.LoadingPanel and the ASPxCaptcha.LoadingPanelImage properties to specify the panel’s settings and image.
Note
The ASPxCaptcha control provides you with comprehensive client-side functionality, implemented using JavaScript code:
- The control’s client-side equivalent is represented by the ASPxClientCaptcha object.
- On the client side, the client object can be accessed directly by the name specified via the ASPxCaptcha.ClientInstanceName property.
- The available client events can be accessed by using the ASPxCaptcha.ClientSideEvents property.
The control’s client-side API is enabled if the ASPxCaptcha.ClientInstanceName property is defined, or any client event is handled.