对此有些困难。来自代码的onServerValidate触发并设置args.IsValid = false但是自定义验证器没有弹出不会在客户端显示错误。我也试图使用AJAX标注扩展器来扩展它。
<asp:CustomValidator ID="cvOffenceList" runat="server"
ErrorMessage="Please check at least one item on the offence list."
Display="None" ForeColor="#CC0000"
onservervalidate="cvOffenceList_ServerValidate"
>*</asp:CustomValidator>
<asp:ValidatorCalloutExtender ID="ValidatorCalloutExtender2" runat="server"
TargetControlID="cvOffenceList">
</asp:ValidatorCalloutExtender>
<asp:CheckBoxList ID="cbOffenceList" runat="server" >
<asp:ListItem>Items1</asp:ListItem>
<asp:ListItem>Items2</asp:ListItem>
<asp:ListItem>Items3</asp:ListItem>
</asp:CheckBoxList>
protected void cvOffenceList_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = false;
// Iterate through the Checkbox List and see if any items are checked
for (int j = 0; j < cbOffenceList.Items.Count; j++)
{
if (cbOffenceList.Items[j].Selected)
{
// If any item is checked then validation is set to true
args.IsValid = true;
}
}
}
protected void btnSubmitCase_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
// Store Session Variables for further use
// Insert Case Info to Table
// Check if Image has a file
}
}