Validating a group of checkboxes in asp net Public adult random chatrooms
You can perform custom validation when you submit the form and prevent submitting if there are no checked checkboxes.For your convenience here is a js Bin example which demonstrates a possible implementation.[Validate At Least One Checked(new string , Error Message Resource Type=typeof(Error Message Resources), Error Message Resource Name="Select At Least One Topic")] public bool Checkbox1 public bool Checkbox2 public bool Checkbox3 public bool Checkbox4 The aim was to get the check boxes all validating and keep the validations and their localization contained in the View Model.This is working, my only concern is that I expected to find an easy google-paste piece of code for this and did not... As a secondary question I am attaching this to only one checkbox field, which I think is fine; but is there any unintended consequences of that (other than that any I'll answer your second question first!Which is why I would put the validation attribute on your class instead of on one of the checkbox.Then, to show your error message on your client HTML you would need to set since the target of your attribute is the instance itself. NET provides a variety of validation Web controls that can be used to validate a user's form field inputs. NET 2.0 for the validation control changes from ASP. NET version 2.0.) Unfortunately, the validation Web controls do not work with the Check Box or Check Box List Web controls. for general information on the validation Web controls and Dissecting Validation Controls in ASP.
I mean, individually, a checkbox doesn't need to be checked, but your model requires one of them to be.I'll review your current code too, because there is three points that I see could be "better" :) By convention, attributes should end with the suffix when you use it (as shown in my example, which compiles! Also, your brackets are following the Java standard, not the C# one. Now you can ask questions directly to me on my new site ASPForums. At this point, we have all of the needed server-side functionality for the Check Box Validator control.To add client-side functionality, however, we must add a bit more code.