Back to Devexpress

ASPxTextBox Class

aspnet-devexpress-dot-web-8eea0004.md

latest9.5 KB
Original Source

ASPxTextBox Class

A text box editor.

Namespace : DevExpress.Web

Assembly : DevExpress.Web.v25.2.dll

NuGet Package : DevExpress.Web

Declaration

csharp
public class ASPxTextBox :
    ASPxTextBoxBase
vb
Public Class ASPxTextBox
    Inherits ASPxTextBoxBase

Remarks

The ASPxTextBox control allows end users to enter text in a single line.

Create a Text Box

Design Time

The ASPxTextBox control is available on the DX.25.2: 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 markup in the page’s source code.

Note

To properly function, DevExpress controls require that special modules, handlers and options are registered in the the Web.config file. Switch the Microsoft Visual Studio IDE to the Design tab to automatically update the Web.config file with the required DevExpress information.

aspx
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Text="Test text" Width="170px">
</dx:ASPxTextBox>

Run Time

csharp
using DevExpress.Web;
...
protected void Page_Load(object sender, EventArgs e)
{
ASPxTextBox textBox = new ASPxTextBox();
textBox.ID = "ASPxTextBox1";
form1.Controls.Add(textBox);
textBox.Width = Unit.Pixel(170);
textBox.Text = "Test text";
}
vb
Imports DevExpress.Web
...
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    Dim textBox As ASPxTextBox = New ASPxTextBox()
    textBox.ID = "ASPxTextBox1"
    form1.Controls.Add(textBox)
    textBox.Width = Unit.Pixel(170)
    textBox.Text = "Test text"
End Sub

Client-Side API

The ASPxTextBox ‘s client-side API is implemented with JavaScript language and exposed by the ASPxClientTextBox object.

|

Availability

|

Available by default.

| |

Client object type

|

ASPxClientTextBox

| |

Access name

|

ASPxTextBox.ClientInstanceName

| |

Events

|

ASPxTextBox.ClientSideEvents

|

Data-Bound Mode

You can bind the text box control to data fields in a data source.

aspx
<dx:ASPxTextBox ID="ASPxTextBox" runat="server" Width="100%" Value='<%# Bind("Name") %>' >
</dx:ASPxTextBox>

More details | See demo

Native Render

Set the Native property to true to render the ASPxTextBox as a native HTML text input element. This reduces the amount of generated HTML code and improves the editor’s performance. In native mode, the text box’s appearance depends on how the client browser renders native HTML elements.

aspx
<dx:ASPxTextBox ID="TextBox" runat="server" Native="True" Width="166" Text="TextBox">
</dx:ASPxTextBox>

Native Mode | See demo

Null Prompt Text

The text box displays a prompt text if its value is null and if the editor is not focused. The prompt text disappears when the editor receives focus. Use the NullText property to define the prompt text.

aspx
<dx:ASPxTextBox ID="TextBox" runat="server" NullText="Enter your name..." Width="166" Text="TextBox">
</dx:ASPxTextBox>

See demo

Masked Input

The text box editor allows you to use masks (MaskSettings when you edit the editor. Use masks to specify format to enter a value to the editor.

aspx
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="100%" Caption="Zip Code">
    <MaskSettings Mask="00000" ErrorText="Please input missing digits" />
</dx:ASPxTextBox>

Learn more | See demo

Display Format

Use the DisplayFormatString property to format display values in the text box.

aspx
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Text="123456" DisplayFormatString="[00 - 00 - 00]" Width="100%" />

See demo

Built-in Validation

The text box allows you to validate its data both on the client and server side.

aspx
<dx:ASPxTextBox runat="server" Width="100%" ID="NameTextBox" OnValidation="NameTextBox_Validation">
    <ValidationSettings SetFocusOnError="True" 
      ErrorText="Name must be at least 
 two characters long" Display="Dynamic" ErrorTextPosition="Bottom">
        <RequiredField IsRequired="True" ErrorText="Name is required" />
    </ValidationSettings>
    <ClientSideEvents Validation="onNameValidation" />
    <InvalidStyle BackColor="LightPink" />
</dx:ASPxTextBox>
js
function onNameValidation(s, e) {
    var name = e.value;
    if (name == null)
        return;
    if (name.length < 2)
        e.isValid = false;
}
csharp
protected void NameTextBox_Validation(object sender, ValidationEventArgs e) {
    if ((e.Value as string).Length < 2)
         e.IsValid = false;
}
vb
Protected Sub NameTextBox_Validation(ByVal sender As Object, ByVal e As ValidationEventArgs)
    If (TryCast(e.Value, String)).Length < 2 Then e.IsValid = False
End Sub

Learn more | See demo

Implements

Show 17 items

IComponent

IDisposable

IParserAccessor

IDataBindingsAccessor

IControlBuilderAccessor

IControlDesignerAccessor

IExpressionsAccessor

IAttributeAccessor

IUrlResolutionService

INamingContainer

IPostBackDataHandler

IPostBackEventHandler

ICallbackEventHandler

IPropertiesOwner

IDataSourceViewSchemaAccessor

IEditableTextControl

ITextControl

Inheritance

Show 15 items

Object Control WebControl ASPxWebControlBase ASPxWebControl ASPxDataWebControlBase ASPxDataWebControl ASPxEditBase ASPxEdit ASPxTextEdit ASPxPureTextBoxBase ASPxTextBoxBase ASPxTextBox BootstrapTextBox

MVCxTextBox

See Also

ASPxTextBox Members

TextBoxProperties

Text Box

DevExpress.Web Namespace