服务器标签格式不正确 - RegularExpressionValidator

时间:2012-02-08 14:49:49

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

我正在尝试编写一个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>

这有什么问题? 我四处搜寻,找不到任何理由说明这种情况不好。

3 个答案:

答案 0 :(得分:5)

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)." 

答案 1 :(得分:0)

您的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).'

答案 2 :(得分:0)

试试这个

<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> 

OR

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