473,626 Members | 3,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.IsVal id =
false;)
however it seemed like it never even fired that validator, even though the
submit button CausesValidatio n = true,
Thanks,
Ronnyek
Nov 17 '05 #1
2 8899
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:dropdownli st id="DropDownLis t1" runat="server"
AutoPostBack="T rue"></asp:dropdownlis t>
<asp:customvali dator id="CustomValid ator2" runat="server"
ClientValidatio nFunction="Cust omValidator2_Va lidate">Error</asp:customvalid a
tor>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

The custom validator is not set to any ControlToValida te 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 CustomValidator 2_Validate(sour ce, arguments) {
if (document.all(" DropDownList1") .value == "Two")
{
arguments.IsVal id = false;
}
else
{
arguments.IsVal id = 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**********@c harter.net>
Newsgroups: microsoft.publi c.dotnet.framew ork.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.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!t-onlin
e.de!130.59.10. 21.MISMATCH!ira zu.switch.ch!sw itch.ch!in.100p roofnews.com!td s
net-transit!newspee r.tds.net!sn-xit-02!sn-xit-06!sn-post-02!sn-post-01!super
news.com!corp.s upernews.com!no t-for-mail Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:1852 57
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.IsVal id =
false;)
however it seemed like it never even fired that validator, even though the
submit button CausesValidatio n = 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:dropdownli st id="DropDownLis t1" runat="server"
AutoPostBack="T rue"></asp:dropdownlis t>
<asp:customvali dator id="CustomValid ator2" runat="server"
ClientValidatio nFunction="Cust omValidator2_Va lidate">Error</asp:customvalid a
tor>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

The custom validator is not set to any ControlToValida te 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 CustomValidator 2_Validate(sour ce, arguments) {
if (document.all(" DropDownList1") .value == "Two")
{
arguments.IsVal id = false;
}
else
{
arguments.IsVal id = 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**********@c harter.net>
Newsgroups: microsoft.publi c.dotnet.framew ork.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.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!t-onlin
e.de!130.59.10. 21.MISMATCH!ira zu.switch.ch!sw itch.ch!in.100p roofnews.com!td s
net-transit!newspee r.tds.net!sn-xit-02!sn-xit-06!sn-post-02!sn-post-01!super
news.com!corp.s upernews.com!no t-for-mail Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:1852 57
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.IsVal id =
false;)
however it seemed like it never even fired that validator, even though the
submit button CausesValidatio n = 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
269
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 where (client side or server side) you will do the validations and how you will submit a form. 1)In ASP ,most of the validations we will do at client side.What in .NET?, because in .NET we have validation controls. 2)How we will submit a form. It...
1
1618
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 dropdownlist, so that it does not accept "please select" as a valid selection and will display a messge to the user. thank you very much
1
1432
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 validation of a particular control (textbox, dropdownlist, etc.) the cursor does not return to that particular control. It returns back within in the page in which the user can then delete the control. What can I do to fix a problem like this?...
4
9024
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 to the server WITHOUT the validators invoking their validation. It seems that the easiest solution would have been for MS to simply give the DropDownList control a "CausesValidation" property, but it does not have one. How can I invoke the...
1
328
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 JavaScript function calls the submit() method of the form. For this HtmlSelect control I have also programmed the ServerChange event, which is able to dynamically set up the form.
5
2134
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 e.ItemType = ItemType.FieldItem And e.ColumnName = "IDEvent" Then Dim ctlEvent As DropDownList = CType(e.Control, DropDownList) Dim compVal AS CompareValidator = New CompareValidator()
12
2041
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 validation controls to do this? Thanks.
1
1294
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 (document.getElementById('dnn_ctr-1_Register_ddReferral').value = document.getElementById("dnn_ctr-1_Register_txtReferral").value;) and the validation control will valify the dropdownlist if it's empty. I found there is a problem the server side...
0
1081
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 validation error that i get is this: # Error Line 263 column 86: there is no attribute "language".
0
8268
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8202
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4093
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1812
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.