List box validation in asp.net
-
29-09-2019 - |
Question
Hi how to set required feild validator for multi select list box in asp.net?
I tried in default way something like
initial value = "0" for required feild validator. But it is not working for me.
Any example?
Solution
@jestges: chek this link i am sure it will hep you out.
OTHER TIPS
U can use the custom validation for that..
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args) { if (ListBox1.Items.Count == 0) { args.IsValid = false; } else { args.IsValid = false; } }
may be this will help you
A small correction to your code is in order since it always returns false:
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = (ListBox1.Items.Count > 0);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow