Back to Devexpress

ASPxCaptcha.CodeLength Property

aspnet-devexpress-dot-web-dot-aspxcaptcha-0c5313a3.md

latest3.1 KB
Original Source

ASPxCaptcha.CodeLength Property

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

Declaration

csharp
[DefaultValue(5)]
public int CodeLength { get; set; }
vb
<DefaultValue(5)>
Public Property CodeLength As Integer

Property Value

TypeDefaultDescription
Int325

An integer value that represents the displayed code length.

|

Example

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).

csharp
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;
...
}
aspx
<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

Captcha Control

ASPxCaptcha Class

ASPxCaptcha Members

DevExpress.Web Namespace