Teemu is correct about using the RequiredFieldValidator so I'm not sure why
it doesn't work for you. On the server side, the validator gets a text value
of an empty string back from the ListBox control and that validator will
report an error. If you set its Enabled or Visible property to false, it
will stay silent.
You've described shutting of client-side validation to handle multiple
submit buttons. I'm guessing that you have submit buttons associated with
specific validators. Microsoft is introducing a solution for this that
allows client-side validation. Its called "Validation Groups" and is in
ASP.NET 2.0.
Since ASP.NET 2.0 is a long way off, I have a solution that is available
today. My product, "Professional Validation And More"
(
http://www.peterblum.com/vam/home.aspx), is a replacement for Microsoft's
validators that overcomes its many limitations and greatly expands the
features available to validation. For example, it includes "validation
groups" and the RequiredListValidator, which handles your listbox issue by
determining the selected item's index, not the text value. "Professional
Validation And More" is designed to greatly reduce the coding you do now
creating custom validators and hacks to work around Microsoft's validator
limitations.
--- Peter Blum
www.PeterBlum.com Email: PLBlum@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx [quoted text, click to view] "me" <wtumaxi@forum.dk> wrote in message
news:6fd6d897.0402182349.70c136f4@posting.google.com...
> It has no default selection. If the user dosent make a selection
> then the listbox returns an empty string. If I explicitly
> program the initial value of requiredfieldvalidator to be an empty
> string then i always get isvalid=false. If I program initial value to
> be something that cant be selected in the list then i get True
> all the time, no matter if the user selects anything or not.
>
> I have tested the same requiredfieldvalidator against a textbox
> in which case it works fine.
>
> btw. i have switched clientside scriping off because i want to
> ignore the requiredfieldvalidator if a certain submit button is
> pressed (i have several in the page).
>
> "Teemu Keiski" <joteke@aspalliance.com> wrote in message
news:<ODDmmql9DHA.3820@tk2msftngp13.phx.gbl>...
> > Hi,
> >
> > it should work if you have set the InitialValue property of the
> > RequiredFieldValidator to point which selection (ListItem's value) is
the
> > default one (to distinguish if something has been selected)
> >
> > --
> > Teemu Keiski
> > MCP, Microsoft MVP (ASP.NET), AspInsiders member
> > ASP.NET Forum Moderator, AspAlliance Columnist
> >
> > "me" <wtumaxi@forum.dk> wrote in message
> > news:6fd6d897.0402172350.67017c29@posting.google.com...
> > Is there any particular reason why a requiredfieldvalidator
> > cant validate a listbox? I have bound the two together but
> > the validator always returns false on isvalid and so does the
> > Page, no matter if the user selects an item in the listbox
> > or not.