aspnet-devexpress-dot-web-dot-aspxcaptcha-0c5313a3.md
Gets or sets the code length displayed within the editor’s challenge image.
Namespace : DevExpress.Web
Assembly : DevExpress.Web.v25.2.dll
NuGet Package : DevExpress.Web
[DefaultValue(5)]
public int CodeLength { get; set; }
<DefaultValue(5)>
Public Property CodeLength As Integer
| Type | Default | Description |
|---|---|---|
| Int32 | 5 |
An integer value that represents the displayed code length.
|
The following part of the ASPxCaptcha - Features online demo illustrates how to customize the characters set used to generate the challenge image’s code (ASPxCaptcha.CharacterSet) and specify this code length (ASPxCaptcha.CodeLength).
This settings are specified within a panel (ASPxTextBox, ASPxSpinEdit editors) and applied to the captcha control via the Apply button (ASPxButton).
protected void btnApply_Click(object sender, EventArgs e) {
...
int parseResult = 0;
if(tbCharacterSet.IsValid)
Captcha.CharacterSet = tbCharacterSet.Text;
if (int.TryParse(seCodeLength.Text, out parseResult))
Captcha.CodeLength = parseResult;
...
}
<dx:ASPxCaptcha ID="Captcha" runat="server" Width="402px">
<ValidationSettings ErrorDisplayMode="Text"></ValidationSettings>
</dx:ASPxCaptcha>
...
<dx:ASPxLabel EnableViewState="False" ID="lblCharacterSet" AssociatedControlID="tbCharacterSet"
runat="server" Text="Character set:" />
...
<dx:ASPxTextBox ID="tbCharacterSet" runat="server"
Width="200px" MaxLength="50">
<ValidationSettings>
<RequiredField IsRequired="True" ErrorText="A character set is required" />
</ValidationSettings>
</dx:ASPxTextBox>
...
<dx:ASPxLabel EnableViewState="False" ID="lblCodeLength" AssociatedControlID="seCodeLength"
runat="server" Text="Code length:" />
...
<dx:ASPxSpinEdit ID="seCodeLength" Width="50px" runat="server"
MinValue="3" MaxValue="7"></dx:ASPxSpinEdit>
...
<dx:ASPxButton ID="btnApply" CssClass="DemoButton" runat="server"
Text="Apply" Width="70px" OnClick="btnApply_Click" />
...
See Also