ValidatorCallout控件是一个用来绑定验证控件的提示控件,让验证的信息的显示可以更加地直观。
属性:
TargetControlID:要绑定的验证控件的ID。
Width:弹出的提示信息的宽度。
HighlightCssClass:弹出的提示信息所应用的样式。
WarningIconImageUrl:弹出信息中的警示图片的地址。
代码实例:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>ValidatorCallout</title>
<style type="text/css">
.cssValidatorCalloutHighlight
{
background-color: #F5FF77;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
用户名:<asp:TextBox ID="TextBoxUserName" runat="server" TextMode="Password" Width="148px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxUserName"
Display="None" ErrorMessage="姓名不能为空<br>请输入姓名"></asp:RequiredFieldValidator><br />
密 码:<asp:TextBox ID="TextBoxPassword" runat="server" TextMode="Password" Width="148px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBoxPassword"
Display="None" ErrorMessage="密码不能为空,请输入密码"></asp:RequiredFieldValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server"
TargetControlID="RequiredFieldValidator1" HighlightCssClass="cssValidatorCalloutHighlight" >
</ajaxToolkit:ValidatorCalloutExtender>
<ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server"
TargetControlID="RequiredFieldValidator2" >
</ajaxToolkit:ValidatorCalloutExtender>
</form>
</body>
</html>
<head runat="server">
<title>ValidatorCallout</title>
<style type="text/css">
.cssValidatorCalloutHighlight
{
background-color: #F5FF77;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</ajaxToolkit:ToolkitScriptManager>
用户名:<asp:TextBox ID="TextBoxUserName" runat="server" TextMode="Password" Width="148px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxUserName"
Display="None" ErrorMessage="姓名不能为空<br>请输入姓名"></asp:RequiredFieldValidator><br />
密 码:<asp:TextBox ID="TextBoxPassword" runat="server" TextMode="Password" Width="148px"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBoxPassword"
Display="None" ErrorMessage="密码不能为空,请输入密码"></asp:RequiredFieldValidator>
<ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender1" runat="server"
TargetControlID="RequiredFieldValidator1" HighlightCssClass="cssValidatorCalloutHighlight" >
</ajaxToolkit:ValidatorCalloutExtender>
<ajaxToolkit:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server"
TargetControlID="RequiredFieldValidator2" >
</ajaxToolkit:ValidatorCalloutExtender>
</form>
</body>
</html>
运行结果: