473,215 Members | 1,243 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,215 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 8885
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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.