RequiredFieldValidator wont bind ListBox???

M

me

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.
 
T

Teemu Keiski

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

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.
 
M

me

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).
 
P

Peter Blum

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: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top