Validating a group of checkboxes in asp net

Posted by / 02-Sep-2017 13:33

Validating a group of checkboxes in asp net

Recently I had this requirement where in a single button click I need to call multiple Validation groups. Each user control had its own validation controls and they had their own Validation group defined. NET page where there were 5 user controls and each had their own validation controls embedded in them.This is the methods that performs the server side validation in case Java Script is not enabled on the client, or not supported.In this method I just loop through all the items of the Check Box List and if I find one that is selected then I return true.You could use a Custom Validator control, but a nicer and more reusable approach is to build a custom web control that extends the Base Validator.I found a 2001 article on how to do that (Building a Check Box List Validator Control) but it doesn't work properly on ASP. So I have to make some small changes to make it work on ASP. First thing you have create a class that inherits from Base Validator In this we check if the control is null and if the control can be cast to a Check Box List.): If the checkboxes are linked by id and if the checkboxes are not linked at all. You see, if they share the same id, the required method can be used since it will treat them all as the same element and therefore if even on is checked, there is a value.

First I check if the client validation is enabled, and, if it is, I write on the page the javascript method, and more important, the code to tell the common validation script to call my "cb_verify" function to validate the value of the control.

The Check Box control is a very common control of HTML, unlike radio buttons it can select multiple items on a webpage. NET has many properties and some of them are listed below.

The explorer will have Selection open for you with some default code.

As you can see there are 5 checkboxes and the validation would be to select at least 3 technologies. To find out, how many checkboxes are checked, use length property to find out.

Suggested Post, Nothing shocks me, I'm a Software Engineer. I live in World Wide Web and from there take care of this website.

validating a group of checkboxes in asp net-21validating a group of checkboxes in asp net-42validating a group of checkboxes in asp net-25

This website communicates about my work, learning and experience.