473,398 Members | 2,188 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,398 software developers and data experts.

Form Validation of ASP.NET's DropDownList

I'd like to have a 3 values in a drop down, and have a validator not allow a
form submit unless its 2 of the 3 values (eg, one of the values says "select
one")

I used custom validator and did a if(args.value == "0"){args.IsValid =
false;)
however it seemed like it never even fired that validator, even though the
submit button CausesValidation = true,
Thanks,
Ronnyek
Nov 17 '05 #1
2 8892
Hi Wes,

First off, you can't have the drop lists set to autopostback. This is
because drop lists do not cause validation and you need validation.

Here's how I setup your scenario.

I have a drop list, a custom validator and a button as follows (the drop
list I load with two values "One" and "Two"):

<asp:dropdownlist id="DropDownList1" runat="server"
AutoPostBack="True"></asp:dropdownlist>
<asp:customvalidator id="CustomValidator2" runat="server"
ClientValidationFunction="CustomValidator2_Validat e">Error</asp:customvalida
tor>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

The custom validator is not set to any ControlToValidate so that it will
execute even if the control it is validating is blank.

Then I set the validator's client script as follows
function CustomValidator2_Validate(source, arguments) {
if (document.all("DropDownList1").value == "Two")
{
arguments.IsValid = false;
}
else
{
arguments.IsValid = true;
}
}

---
I hope this helps.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Wes Weems" <ww**********@charter.net>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Form Validation of ASP.NET's DropDownList
Date: Sun, 19 Oct 2003 22:39:56 -0700
Organization: Posted via Supernews, http://www.supernews.com
Message-ID: <vp************@corp.supernews.com>
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
X-Complaints-To: ab***@supernews.com
Lines: 14
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!130.59.10.21.MISMATCH!irazu.switch.ch!switch. ch!in.100proofnews.com!tds
net-transit!newspeer.tds.net!sn-xit-02!sn-xit-06!sn-post-02!sn-post-01!super
news.com!corp.supernews.com!not-for-mail Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:185257
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I'd like to have a 3 values in a drop down, and have a validator not allow a form submit unless its 2 of the 3 values (eg, one of the values says "select one")

I used custom validator and did a if(args.value == "0"){args.IsValid =
false;)
however it seemed like it never even fired that validator, even though the
submit button CausesValidation = true,
Thanks,
Ronnyek


Nov 17 '05 #2
Hi Wes,

First off, you can't have the drop lists set to autopostback. This is
because drop lists do not cause validation and you need validation.

Here's how I setup your scenario.

I have a drop list, a custom validator and a button as follows (the drop
list I load with two values "One" and "Two"):

<asp:dropdownlist id="DropDownList1" runat="server"
AutoPostBack="True"></asp:dropdownlist>
<asp:customvalidator id="CustomValidator2" runat="server"
ClientValidationFunction="CustomValidator2_Validat e">Error</asp:customvalida
tor>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

The custom validator is not set to any ControlToValidate so that it will
execute even if the control it is validating is blank.

Then I set the validator's client script as follows
function CustomValidator2_Validate(source, arguments) {
if (document.all("DropDownList1").value == "Two")
{
arguments.IsValid = false;
}
else
{
arguments.IsValid = true;
}
}

---
I hope this helps.

Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer’s security.

This posting is provided "AS IS", with no warranties, and confers no rights.
--------------------
From: "Wes Weems" <ww**********@charter.net>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Form Validation of ASP.NET's DropDownList
Date: Sun, 19 Oct 2003 22:39:56 -0700
Organization: Posted via Supernews, http://www.supernews.com
Message-ID: <vp************@corp.supernews.com>
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
X-Complaints-To: ab***@supernews.com
Lines: 14
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
e.de!130.59.10.21.MISMATCH!irazu.switch.ch!switch. ch!in.100proofnews.com!tds
net-transit!newspeer.tds.net!sn-xit-02!sn-xit-06!sn-post-02!sn-post-01!super
news.com!corp.supernews.com!not-for-mail Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet:185257
X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet

I'd like to have a 3 values in a drop down, and have a validator not allow a form submit unless its 2 of the 3 values (eg, one of the values says "select one")

I used custom validator and did a if(args.value == "0"){args.IsValid =
false;)
however it seemed like it never even fired that validator, even though the
submit button CausesValidation = true,
Thanks,
Ronnyek


Nov 17 '05 #3

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

Similar topics

2
by: MAIL2SURI | last post by:
HI, I recently moved to .NET from asp.When ever I am doing coding in .NET,every time my mind is diverting to ASP side and I am comapring with ASP coding structure.In general, in .NET ,how and...
1
by: dopey | last post by:
I have a dropdownlist on my asp form. the first item of the list is text like "please select", the other items are populated by a database. Can i use the RequiredFieldValidator control with my...
1
by: Leon Shaw | last post by:
I built a normal registration form containing the normal textboxes, dropdownlists, and validation controls. However, when a user submits the form in which some field does not pass the client side...
4
by: Scott M. | last post by:
If I put RequiredFiledValidators on a page and set them up with corresponding TextBoxes everything works just fine. If I add a DropDownList and set its AutoPostBack to True, I am able to post data...
1
by: peshrad | last post by:
Hi ! I'm using Visual Studio .NET to program a Web application coding in C#. In my form I use an HtmlSelect control that calls a JavaScript function when the selected item changes. This...
5
by: TJS | last post by:
I need to add validation to drodownlist control but it sends back an error message that says: "System.Web.UI.WebControls.DropDownList' does not allow child controls" the code is : If...
12
by: Dabbler | last post by:
I need to insure that at least one of three phone number fields has a value (requiredfield) but I'm not sure of a way to implement this without server side logic. Is there a way to use the...
1
by: js | last post by:
Hi, I have a text box and DropDownList control and a validation control, When user entering a number in the text box, based on the entered number, the dropdrownlist value will change...
0
by: eurorscg | last post by:
Hi, i have this dropdownlist that breaks xhtml w3c validation.because it generates a select tag with a javascript property. this only happens when autopostback is set to true. so the the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.