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