473,396 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

can you use a required field validator for a dropdown list box?

I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there anyway to set this up or do you need to use client side validation? Thanks
--
Paul G
Software engineer.
Nov 18 '05 #1
6 21301
You can use a required field validator on dropdowns, but you should have a
first item in the dropdown such as --- Choose From Below --- and then you'll
need to add this to your page_load event

dropdown.selectedItem.value = ""

Then the validator won't recognize the first item as a valid item and it
will work.

By the way, all the validators do their validations by client-side
JavaScript that is generated for you (except the CustomValidator). They
also do their checks again server side in case someone tries to maliciously
bypass the client code.
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
I am trying to setup a field validator and tried using the control to validate set to a dropdown list box but did not seem to work. Is there
anyway to set this up or do you need to use client side validation? Thanks --
Paul G
Software engineer.

Nov 18 '05 #2
Hi Scott, thanks for the information. Looks like it is almost working correctly, that is if there is no selection and I hit the submit button I get the validation error message. Next a selection is made and the validation error message goes away. I then hit submit which causes the page load to execute again as well as the Me.DropDownList1.SelectedItem.Value = "" and this causes the validation error message to appear again. So the validation error message seems to appear after the submit button is hit.
Thanks
--
Paul G
Software engineer.
"Scott M." wrote:
You can use a required field validator on dropdowns, but you should have a
first item in the dropdown such as --- Choose From Below --- and then you'll
need to add this to your page_load event

dropdown.selectedItem.value = ""

Then the validator won't recognize the first item as a valid item and it
will work.

By the way, all the validators do their validations by client-side
JavaScript that is generated for you (except the CustomValidator). They
also do their checks again server side in case someone tries to maliciously
bypass the client code.
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
I am trying to setup a field validator and tried using the control to

validate set to a dropdown list box but did not seem to work. Is there
anyway to set this up or do you need to use client side validation? Thanks
--
Paul G
Software engineer.


Nov 18 '05 #3
Paul,

Two things.

1) To fix the problem of the selected item being fired a second time wrap it
in an if then so it only fires on page load:

If Not Page.IsPostBack Then
'---Select intial item here
End If

2) Always wrap code that should fire only if the page is valid in this if
then:

If Page.IsValid Then
'---Page is valid: run code
End If

If you don't then server side validation isn't checked and anyone who isn't
running javascript will be able to run the post back even with invalid data.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi Scott, thanks for the information. Looks like it is almost working correctly, that is if there is no selection and I hit the submit button I
get the validation error message. Next a selection is made and the
validation error message goes away. I then hit submit which causes the page
load to execute again as well as the Me.DropDownList1.SelectedItem.Value =
"" and this causes the validation error message to appear again. So the
validation error message seems to appear after the submit button is hit. Thanks
--
Paul G
Software engineer.
"Scott M." wrote:
You can use a required field validator on dropdowns, but you should have a
first item in the dropdown such as --- Choose From Below --- and then you'll need to add this to your page_load event

dropdown.selectedItem.value = ""

Then the validator won't recognize the first item as a valid item and it
will work.

By the way, all the validators do their validations by client-side
JavaScript that is generated for you (except the CustomValidator). They
also do their checks again server side in case someone tries to maliciously bypass the client code.
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
I am trying to setup a field validator and tried using the control to

validate set to a dropdown list box but did not seem to work. Is there
anyway to set this up or do you need to use client side validation?

Thanks
--
Paul G
Software engineer.


Nov 18 '05 #4
Hi Justin, thanks for the information. Just wondering what page is valid means, seems like it is needed to protect against those not running java script.

--
Paul G
Software engineer.
"S. Justin Gengo" wrote:
Paul,

Two things.

1) To fix the problem of the selected item being fired a second time wrap it
in an if then so it only fires on page load:

If Not Page.IsPostBack Then
'---Select intial item here
End If

2) Always wrap code that should fire only if the page is valid in this if
then:

If Page.IsValid Then
'---Page is valid: run code
End If

If you don't then server side validation isn't checked and anyone who isn't
running javascript will be able to run the post back even with invalid data.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi Scott, thanks for the information. Looks like it is almost working

correctly, that is if there is no selection and I hit the submit button I
get the validation error message. Next a selection is made and the
validation error message goes away. I then hit submit which causes the page
load to execute again as well as the Me.DropDownList1.SelectedItem.Value =
"" and this causes the validation error message to appear again. So the
validation error message seems to appear after the submit button is hit.
Thanks
--
Paul G
Software engineer.
"Scott M." wrote:
You can use a required field validator on dropdowns, but you should have a first item in the dropdown such as --- Choose From Below --- and then you'll need to add this to your page_load event

dropdown.selectedItem.value = ""

Then the validator won't recognize the first item as a valid item and it
will work.

By the way, all the validators do their validations by client-side
JavaScript that is generated for you (except the CustomValidator). They
also do their checks again server side in case someone tries to maliciously bypass the client code.
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:31**********************************@microsof t.com...
> I am trying to setup a field validator and tried using the control to
validate set to a dropdown list box but did not seem to work. Is there
anyway to set this up or do you need to use client side validation? Thanks > --
> Paul G
> Software engineer.


Nov 18 '05 #5
Page.IsValid is returns a boolean value indicating if all of the validation
code passed or failed. This is generally used in an If statement:

If Page.IsValid then
'All server validations were successful

Else
'At least one server validation failed

End If

You can also force all the server validation code to run with
Page.Validate().


"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:25**********************************@microsof t.com...
Hi Justin, thanks for the information. Just wondering what page is valid means, seems like it is needed to protect against those not running java
script.
--
Paul G
Software engineer.
"S. Justin Gengo" wrote:
Paul,

Two things.

1) To fix the problem of the selected item being fired a second time wrap it in an if then so it only fires on page load:

If Not Page.IsPostBack Then
'---Select intial item here
End If

2) Always wrap code that should fire only if the page is valid in this if then:

If Page.IsValid Then
'---Page is valid: run code
End If

If you don't then server side validation isn't checked and anyone who isn't running javascript will be able to run the post back even with invalid data.
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi Scott, thanks for the information. Looks like it is almost working

correctly, that is if there is no selection and I hit the submit button I get the validation error message. Next a selection is made and the
validation error message goes away. I then hit submit which causes the page load to execute again as well as the Me.DropDownList1.SelectedItem.Value = "" and this causes the validation error message to appear again. So the
validation error message seems to appear after the submit button is hit.
Thanks
--
Paul G
Software engineer.
"Scott M." wrote:

> You can use a required field validator on dropdowns, but you should have
a
> first item in the dropdown such as --- Choose From Below --- and
then you'll
> need to add this to your page_load event
>
> dropdown.selectedItem.value = ""
>
> Then the validator won't recognize the first item as a valid item

and it > will work.
>
> By the way, all the validators do their validations by client-side
> JavaScript that is generated for you (except the CustomValidator). They > also do their checks again server side in case someone tries to

maliciously
> bypass the client code.
>
>
> "Paul" <Pa**@discussions.microsoft.com> wrote in message
> news:31**********************************@microsof t.com...
> > I am trying to setup a field validator and tried using the control to > validate set to a dropdown list box but did not seem to work. Is there > anyway to set this up or do you need to use client side validation?

Thanks
> > --
> > Paul G
> > Software engineer.
>
>
>


Nov 18 '05 #6
That's right. The client-side validation controls only work in (recent
versions of) IE, and not even IE users will necessarily have
client-side scripting enabled, so we need to use server-side scripting
to double-check the validity of submitted data, for both useability
and security. The Page.Validate method is automatically called to
accomplish this for us, and we access the results through the
Page.IsValid property.

http://msdn.microsoft.com/library/en...validtopic.asp
http://msdn.microsoft.com/library/en...lid_clientside
"Paul" <Pa**@discussions.microsoft.com> wrote in message news:<25**********************************@microso ft.com>...
Just wondering what page is valid means, seems like it is needed to protect against those not running java script.

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: z. f. | last post by:
Hi, i have a field with required field validator. on the client side it's working. when i submit without the required field the page gets back because of not valid, but the message from the...
2
by: Asha | last post by:
greetings i want to use the required field validator control to validate a checkbox. here is the code implemented. <asp:RequiredFieldValidator ID="rfv" ControlToValidate="chkDistiAudit"...
1
by: Sam Collett | last post by:
Is there a way of having a required field validator check to see if at least one of a set of controls has information in it? I'm sure this can somehow be done using a custom validator, but would...
3
by: Skeptical | last post by:
Hello, I have a form and two buttons on it. Button1 submits the data to a database and RequiredFieldValidator is used to make sure all the required fields are filled up, the second button has a...
3
by: Mike Collins | last post by:
Is it possible to use a required field validator and have it make a user answer a comment field based on a drop down value picked? For instance, if the user selects "It was terrible", make them...
7
by: Newbie Coder | last post by:
How do I use a Required Field Validator control in ASP.NET 2.0 to validate an e-mail address entered into a textbox control because there is no VALIDATION EXPRESSION like in previous versions? ...
0
by: nimeshdotnet | last post by:
Hi All, I have a textbox whose readonly property is set to true. This textbox is also guarded by a required field validator. What i m doing that I have a calendar control whose on date selection i...
6
by: mathewgk80 | last post by:
Hi all, I have two textboxes, txtName and txtDescription. i added required field validator to both of them. I have a Gridview in the same page. In tht gridview, i have a template field...
2
by: akshalika | last post by:
Hi, I have a repeater control. it dynamically bind textbox or dropdown base on some condition. i want to bind required field validator dynamically for validate textbox or dropdown. here is my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.