By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,557 Members | 1,406 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,557 IT Pros & Developers. It's quick & easy.

RequiredFieldValidator wont bind ListBox???

P: n/a
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.
Nov 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <wt*****@forum.dk> wrote in message
news:6f**************************@posting.google.c om...
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.
Nov 18 '05 #2

P: n/a
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).

"Teemu Keiski" <jo****@aspalliance.com> wrote in message news:<OD**************@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" <wt*****@forum.dk> wrote in message
news:6f**************************@posting.google.c om...
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.

Nov 18 '05 #3

P: n/a
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: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"me" <wt*****@forum.dk> wrote in message
news:6f**************************@posting.google.c om...
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" <jo****@aspalliance.com> wrote in message

news:<OD**************@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" <wt*****@forum.dk> wrote in message
news:6f**************************@posting.google.c om...
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.

Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.