【问题标题】:The Server Tag is not well formed - RegularExpressionValidator服务器标签格式不正确 - RegularExpressionValidator
【发布时间】:2012-02-08 14:49:49
【问题描述】:

我正在尝试编写一个 RegularExpressionValidator 来检查以确保输入到文本框中的条目是整数(不包含“。”或“,”,只有整数值,如“500”)

但是我遇到过这种情况:

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: The server tag is not well formed.

代码如下:

<asp:TextBox ID="Paymenttb" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID ="PaymentValidator" runat="server" ControlToValidate="Paymenttb" 
ErrorMessage="Payment must be of type Int (No "." or "," for example)." ValidationExpression="^\d+$">*</asp:RegularExpressionValidator>

这有什么问题? 我已经四处寻找,找不到任何原因导致它没有很好地形成。

【问题讨论】:

  • 您的错误信息包含不允许的"

标签: c# asp.net regex server-tags


【解决方案1】:
ErrorMessage="Payment must be of type Int (No "." or "," for example)." 

这部分。您在引用的参数中有引号。

您可以通过将外引号设为单引号来解决此问题:

ErrorMessage='Payment must be of type Int (No "." or "," for example).'

另一种解决方案:转义引用html样式:

ErrorMessage="Payment must be of type Int (No &quot;.&quot; or &quot;,&quot; for example)." 

"

【讨论】:

  • 我不敢相信我没有看到!多么业余的错误。非常感谢。将标记为答案。我想我只是看代码太久了。
【解决方案2】:

您的ErrorMessage 属性格式不正确:

ErrorMessage="Payment must be of type Int (No "." or "," for example)."

您需要转义属性值中的" - 通过将它们加倍来做到这一点:

ErrorMessage="Payment must be of type Int (No ""."" or "","" for example)."

或者,使用单引号来分隔属性值:

ErrorMessage='Payment must be of type Int (No "." or "," for example).'

【讨论】:

    【解决方案3】:

    试试这个

    <asp:TextBox ID="Paymenttb" runat="server"></asp:TextBox>
    
    
    <asp:RegularExpressionValidator ID ="RegularExpressionValidator1" runat="server" ControlToValidate="Paymenttb"  ToolTip="Payment must be of type Int (No '.' or ',' for example)." ValidationExpression="^\d+$">*</asp:RegularExpressionValidator> 
    

    <asp:RegularExpressionValidator ID ="PaymentValidator" runat="server" ControlToValidate="Paymenttb"  ErrorMessage="Payment must be of type Int (No '.' or ',' for example)." ValidationExpression="[0-9]"></asp:RegularExpressionValidator> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-15
      • 2012-12-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多