How do I enable required field validation on a radcheckbox list item when it is part of a radwizard? I want to ensure that the user selects at least one item but when I hit the Next button to go to the next Wizard Step, it does not fire but proceeds to the next Wizard Step. Is this as designed? Please provide assistance or some white paper article that can help.
Hello,
Just sharing the solutions from the duplicate support thread, for better visibility from the community:
Here is one approach you can take to validate a RadCheckBoxList inside a RadWizard:
1. Enable Unobtrusive Validation for your application. We have a dedicated tutorial which goes into more detail on how to do this. For .NET 4.5+, the client-side validation requires just setting the following key in the web.config:
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
2. Use a CustomValidator instead of a RequiredFieldValidator. Using the clientValidationFunction will allow you to determine if a checkbox has been selected using client-side code.
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function RadCheckBoxValidation(sender, e) {
var checkboxlist = $find(sender.controltovalidate);
var selectedList = checkboxlist.get_selectedItems();
if (selectedList.length > 0) {
e.IsValid = true;
} else {
e.IsValid = false;
}
}
</script>
</telerik:RadCodeBlock>
3. Set the same ValidationGroup for the RadWizardStep, RadCheckBoxList, and CustomValidator.
4. Add the RadCheckBoxList as the CustomValidator's ControlToValidate.
<asp:CustomValidator ID="customValidator1" runat="server" ValidationGroup="validationGroup1"
ControlToValidate="Questionnaire" ForeColor="Red" CssClass="questionnaire-validation-message"
ErrorMessage="Please choose at least one of the options displayed" EnableClientScript="true"
ClientValidationFunction="RadCheckBoxValidation" />
5. The RadWizardStep needs to have its CauseValidation property set to true.
<telerik:RadWizardStep StepType="Step" CausesValidation="true" ValidationGroup="validationGroup1">
...
</telerik:RadWizardStep>
For more details on validation with the RadWizard, please take a look at this documentation.
Regards,
Peter Milchev
Progress Telerik