ASPxTextBox ErrorText Not Updated on Lost Focus

本文关键字:Lost Focus on Updated ErrorText Not ASPxTextBox | 更新日期: 2023-09-27 18:11:01

我得到了这个ASPxTextBox:

<dxe:ASPxTextBox ID="txtFirstName" runat="server">
    <ClientSideEvents LostFocus="function(s, e) {
        if (s.GetText() == '')
        {
            s.SetIsValid(false);
            s.errorText = 'Please enter First Name.';
        }
    }"></ClientSideEvents>
    <ValidationSettings ErrorDisplayMode="ImageWithTooltip">
    </ValidationSettings>
</dxe:ASPxTextBox>

但是显示的errorText不是我在LostFocus事件中设置的。相反,默认的errorText在工具提示中显示为"无效值"。

任何想法?由于

ASPxTextBox ErrorText Not Updated on Lost Focus

为了完成这项任务,有必要:

启用" required "验证(将ValidationSettings.RequiredField.IsRequired属性设置为" true ";

指定" required " errorText (ValidationSettings.RequiredField.ErrorText);

通过设置ValidationSettings强制编辑器验证。ValidateOnLeave属性设置为" true ":

<dxe:ASPxTextBox ID="txtFirstName" runat="server">
    <ClientSideEvents LostFocus="function(s, e) {
        s.Validate();
    }"></ClientSideEvents>
    <ValidationSettings ErrorDisplayMode="ImageWithTooltip" ValidateOnLeave="true">
        <RequiredField IsRequired="true" ErrorText="Please enter First Name." />
    </ValidationSettings>
</dxe:ASPxTextBox>

我碰巧解决了这个问题:

        if (s.GetText() == '')
        {
            s.errorText = 'Please enter First Name.';
            s.SetIsValid(false);
        }

先修改errorText的值,再将ASPxTextBoxIsValid属性设置为false

我想嘲笑我的愚蠢!OMG)

谢谢那些帮助我的人。:)