0

Having some difficulty with this. The onServerValidate from code behind fires and sets the args.IsValid = false however the Custom Validator doesn't pop-up doesn't display the error on the client side. I am also trying to extend it using the AJAX callout extender.

<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
    }
}
4

0 回答 0