C# 带有Callout Extender的复选框列表的自定义验证器
在这方面有一些困难。onServerValidate from code behind会激发并设置args.IsValid=false,但是自定义验证器不会弹出,也不会在客户端显示错误。我还尝试使用AJAX callout extender对其进行扩展C# 带有Callout Extender的复选框列表的自定义验证器,c#,asp.net,ajax,C#,Asp.net,Ajax,在这方面有一些困难。onServerValidate from code behind会激发并设置args.IsValid=false,但是自定义验证器不会弹出,也不会在客户端显示错误。我还尝试使用AJAX callout extender对其进行扩展 <asp:CustomValidator ID="cvOffenceList" runat="server" ErrorMessage="Please check at least one item on the
<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
}
}
*
项目1
项目2
项目3
受保护的void cvOffenceList_ServerValidate(对象源,ServerValidateEventArgs args)
{
args.IsValid=false;
//遍历复选框列表,查看是否选中了任何项
对于(int j=0;j
我假设您指的是Validator Extender TargetControlID?它应该扩展定制验证器cvOffenceList。自定义验证器的targetcontrolID是复选框列表。您可以发布您的.aspx标记吗?很遗憾,它太长,无法发布页面的完整标记。但是,这是唯一一个不会弹出的验证器。所有其余的常规验证器都可以扩展。