<%@ Page Language="C#" %>
<!-- 引用自定义的控件，将Register指令的TagPrefix属性设为XC，Namespace、Assembly属性全部设定为ex35 -->
<%@ Register TagPrefix="XC" Namespace="ex35" Assembly="ex35" %>

<script runat="server">

protected void OnClick(object sender, EventArgs e)
{
//刷新页面，进行验证
	if (IsValid)
	{

	}

}

protected void MyCustomValidator(object sender, ServerValidateEventArgs args)
{
//使用自定义验证，判断和要验证的值是否一致	
	if (args.Value == "validator")
		args.IsValid = true;
	else
		args.IsValid = false;
}

</script>

<html>

<head>
<title>第三十五例 程序构架与代码分离（五）</title>
</head>

<body>
<BR><p></P>
      <h3><font face="Verdana">第三十五例 程序构架与代码分离（五）</font></h3><BR>
<form runat="server">

<asp:ValidationSummary runat="server"
	HeaderText="验证过程发现错误" />

<table cellpadding="2">
<tr>
	<td><asp:Label Text="需要验证:" id="labelField1" runat="server" /></td>
	<td><asp:TextBox runat="server" id="Field1" /></td>
</tr>

<tr>
	<td><asp:Label Text="自定义验证控件:" id="LabelCustomValidator" runat="server" /></td>
	<td><asp:TextBox runat="server" id="Field2" runat="server" /></td>
</tr>

<tr>
	<td colspan="2" height="20" valign="bottom">
		<asp:Button runat="server" Text="开始验证" OnClick="OnClick" />
	</td>
</tr>
</table>

<XC:RequiredFieldValidator	runat="server"
	ErrorMessage="需要验证不能为空"
	ControlToValidate="field1"
	LabelControl="labelField1"
	EnableClientScript="false"
	UseErrorIndicator="true"
	ErrorLabelColor="tan"
	Display="none" />

<XC:CustomValidator runat="server"
	ErrorMessage="自定义验证的值必须是 'validator'"
	ControlToValidate="field2"
	LabelControl="LabelCustomValidator"
	UseErrorIndicator="true"
	OnServerValidate="MyCustomValidator"
	Display="none" />

</form>

</body>

</html>