2012-02-08 49 views
0

我正在嘗試編寫一個RegularExpressionValidator,它檢查以確保輸入到文本框是整數(不包含「。」或「,」,只有像「500」 )服務器標籤格式不正確 - RegularExpressionValidator

但我也遇到過這樣的:

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> 

這有什麼問題嗎? 我搜索了四周,找不到任何理由爲什麼這種形式不好。

+1

你的錯誤信息中包含'「'這是不允許的 – Shai 2012-02-08 14:51:32

回答

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

"

+0

我不能相信我沒有看到!什麼是業餘的錯誤。非常感謝。將標記爲答案。我認爲我剛剛查看代碼的時間太長了。 – Mac 2012-02-08 14:58:48

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).' 
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> 
相關問題