2011-06-16 71 views
0
<asp:CustomValidator ID="PresZipValidator" ControlToValidate="txtZip" 
       runat="server" ErrorMessage="Required Field" EnableClientScript="false" 
       ForeColor="Red"></asp:CustomValidator> 

我的验证将不会显示在我的网页form..any建议?我有一个按钮事件,看看页面是否有效,什么都没有显示。自定义验证将不会显示

+0

这个验证器的处理程序是什么? – 2011-06-16 16:01:19

+0

protected void btnContinue_Click(object sender,EventArgs e) {if(txtZip.Text!=“”) { PresZipValidator.IsValid = true; } else { PresZipValidator.IsValid = false; } – 2011-06-16 16:07:33

+0

我想你要设置'Text =“必填字段”',如果你使用'ValidationSummary',你只使用'ErrorMessage'。另外,你可以使用asp:RequiredFieldValidator来实现你想要的功能,然后你不需要服务器验证功能。 – 2011-06-16 16:13:51

回答

0

首先 - 如果您的验证是需要该字段,请考虑使用RequiredFieldValidator控件。

Text属性是直接从验证器控件显示的内容。您可以使用ValidationSummary控件来显示所有失败验证程序的ErrorMessage属性。

对于CustomValidator控件,您应该考虑实现客户端JavaScript验证(如果可能),并使用ClientValidationFunction属性指向它。