Bug Report T747868
Visible to All Users

ASPxTextBox - The client-side GetText method returns an empty value if a text decoration (for example, a null text) is applied to editor

created 6 years ago

CLONED FROM ASPxTextBox - Value is always null when text is pasted into the editor
To reproduce the issue do the following:

  1. Specify a null text for the ASPxTextBox editor using the NullText property value.
  2. Invoke the GetText method, for example, in the client-side UserInput event handler:
JavaScript
function OnUserInput(s, e) { alert(s.GetText()); }

Answers approved by DevExpress Support

created 6 years ago

The main specificity of the GetText method is that this method returns a string calculated based on a current editor's value and the editor's formatting settings (mask settings, the DisplayFormatString and EditFormatString properties, etc.).
For example, if an end-user types "1111111111" in the ASPxTextBox editor with the following settings:

ASPx
<dx:ASPxTextBox ID="ASPxTextBox1" runat="server" Width="170px"> <MaskSettings Mask="+1 (999) 000-0000" IncludeLiterals="None" /> </dx:ASPxTextBox>

the GetText method will return "+1 (111) 111-1111"
the GetValue method will return "1111111111"
If an end-user types "5" in the ASPxSpinEdit editor with the following settings:

ASPx
<dx:ASPxSpinEdit ID="ASPxSpinEdit1" runat="server" Number="0" DisplayFormatString="C2" />

the GetText method will return "$5.00"
the GetValue  method will return 5
If an end-user types "2019-7-17" in the ASPxDateEdit editor with the following settings:

ASPx
<dx:ASPxDateEdit ID="ASPxDateEdit1" runat="server" EditFormatString="yyyy - MM - dd"></dx:ASPxDateEdit>

the GetText method will return "2019 - 07 - 17"
the GetValue  method will return a date time value in a local time zone (for ex., Wed Jul 17 2019 10:00:00 GMT-0400 (Eastern Daylight Time))

If an end-user types "2" in the ASPxCombobox editor with the following settings:

ASPx
<dx:ASPxComboBox ID="ASPxComboBox1" runat="server"> <Items> <dx:ListEditItem Text="Value 1" Value="1" /> <dx:ListEditItem Text="Value 2" Value="2" /> </Items> </dx:ASPxComboBox>

the GetText method will return "Value 2"
the GetValue  method will return 2

Based on the mentioned specifics, it is required to synchronize a text entered by an end-user with an editor's value before using the GetText method.
For example, if an editor loses focus, its value is automatically calculated (synchronized) based on the entered text.

If you invoke the GetText method before a new editor's value is calculated (i.e. synchronized with the editor's display text), for example, in the client-side UserInput, KeyDown, KeyPress, KeyUp event handlers, this method will return an empty value or a previous editor's text.

In such scenarios, we recommend obtaining an editor's text directly from the editor's input element:

C#
function OnUserInput(s, e) { var currentText = s.GetInputElement().value; }

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.