【问题标题】:How do you insert a newline character within the RegularExpressionValidator ErrorMessage Field?如何在 RegularExpressionValidator ErrorMessage 字段中插入换行符?
【发布时间】:2017-08-23 01:27:27
【问题描述】:

考虑下面的代码:

<asp:RegularExpressionValidator 
        ID="MyTestId"  
        ValidationGroup="MyTestGroup" 
        ErrorMessage="You are a silly user. You entered the wrong format for this problem. Please try again. Using this format! ELRLDKX##Z"
        ValidationExpression="some unrelated regex"
        runat="server"
        ControlToValidate="MyTestTextbox">
</asp:RegularExpressionValidator> 

有没有办法在 ErrorMessage 字符串中插入某种转义字符以确保 请重试。使用这种格式! ELRLDKX##Z 在另一行?我试过了,\n没有运气。

【问题讨论】:

    标签: asp.net .net webforms servercontrols


    【解决方案1】:

    验证器位于网页上,因此您只需将 html 代码添加到文本中,例如 &lt;br /&gt;

    ErrorMessage="You are a silly user. You entered the wrong format for this problem.<br />Please try again. Using this format! ELRLDKX##Z"
    

    【讨论】:

    • 这很好用,但是,我遇到的另一个问题是,当我使用它时,错误消息的边界会出现在两行上。有什么解决办法吗?
    • 对不起,我不太明白你的意思...但是验证器有一个Display 属性,也许将它设置为dynamic 可以帮助?
    • 所以,我将显示设置为动态。然后我想给我的验证者一些“天赋”,带有边框和背景颜色。发生的事情是我得到了一些类似的东西:---------------------------- |你是一个愚蠢的用户 -------------- 你输入了错误的格式............| --------------------------------------------------------
    • 寄宿生跑到下一行的地方。我尝试使用 div 在服务器上运行,但是,问题是隐藏 div 会导致控件关闭。
    • 背景色:红色;文本对齐:左;文本换行:正常;边框:实心;显示:块;颜色:黑色;边距底部:10px;填充:2px;
    猜你喜欢
    • 2017-08-23
    • 1970-01-01
    • 2011-05-04
    • 1970-01-01
    • 2018-05-25
    • 1970-01-01
    • 1970-01-01
    • 2017-11-14
    • 2013-05-23
    相关资源
    最近更新 更多