requiredvalidator on listbox: validating whether the listbox has items or not
I think a requiredvalidator applied to a listbox validates whether the listbaox has an iemselected or not, meaning that if I have items on my listbox but none is selected then the validation fails.
Instead of that, I want to implement The following behaviour :
If the listbox contains items then I want the validation to pass but if it has no items, I want the validation to fail.
Any suggestion pls?
Thank thee :)
Re: requiredvalidator on listbox: validating whether the listbox has items or not
Hi tutus,
Maybe I'm missing something but, the number of items in a listbox is
not something the user can change (unless you have written some extra code for that).
Therefore, it's not supposed to be validated. :)
Re: requiredvalidator on listbox: validating whether the listbox has items or not
But it can be manipulated using javascript from elsewhere on the page.
Use a custom validator. The custom validator allows for both client side scripts and server side scripts. I suggest you write both.
In the client side script (javascript) you can check for
document.getElementById('the DDL ID').options.length > 0
In the server side code, you simply do an Items.Count.