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