473,732 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList validation (separate from page)

Liz
I have a page with several dropdownlists, several text boxes and
several buttons which perform calculations. I need to validate one
dropdownlist (not the whole page) with the click of one button. I have
a separate submit button which should validate the other fields.
This page on MSDN does what I want - almost!

http://msdn.microsoft.com/library/de...ationTopic.asp

I added a dropdownlist, customvalidator and another asp:button, but the
validation control does not work when I click on the button. (it works
when I change the value in the dropdown)
Can anyone help please?

Many thanks.

----------------------WEB FORM-----------------------------
<html>
<head>
<script LANGUAGE="javas cript">
function isItemSelected( source, arguments){
alert(source,ar guments)
if (arguments.Valu e < 1)
{
arguments.IsVal id = false;
}
else
{
arguments.IsVal id = true;
}
}
-->

</script>
</head>

<body>

<form RUNAT="server" ID="Form1">

<h3> Button CausesValidatio n Example </h3>

<table BORDER="1" CELLPADDING="10 ">
<tr>
<td>
<b>Enter city to query.</b> <br>
<asp:textbox ID="CityTextBox "
RUNAT="server"/>
<asp:requiredfi eldvalidator ID="CityReqVali dator"
CONTROLTOVALIDA TE="CityTextBox "
ERRORMESSAGE="< br>Please enter a city."
DISPLAY="Dynami c"
ENABLECLIENTSCR IPT="False"
RUNAT="server"/>
</td>
<td VALIGN="bottom" >
<asp:button ID="CityQueryBu tton"
TEXT="Submit"
CAUSESVALIDATIO N="False"
ONCLICK="Submit Button_Click"
RUNAT="server"/>
</td>
</tr>

<tr>
<td>
<b>Enter state to query.</b> <br>
<asp:textbox ID="StateTextBo x"
RUNAT="server"/>
<asp:requiredfi eldvalidator ID="StateReqVal idator"
CONTROLTOVALIDA TE="StateTextBo x"
ERRORMESSAGE="< br>Please enter a state."
DISPLAY="Dynami c"
ENABLECLIENTSCR IPT="False"
RUNAT="server"/>
</td>
<td VALIGN="bottom" >
<asp:button ID="StateQueryB utton"
TEXT="Submit"
CAUSESVALIDATIO N="False"
ONCLICK="Submit Button_Click"
RUNAT="server"/>
</td>
</tr>
<tr>
<td><asp:DropDo wnList id="DropDownLis t1" runat="server">
<asp:listitem VALUE ="0">Select</asp:listitem>
<asp:listitem VALUE ="1">UK</asp:listitem>
<asp:listitem VALUE ="2">USA</asp:listitem></asp:DropDownLis t>

<asp:CustomVali dator id="CustomValid ator1"
runat="server"
ErrorMessage="* "
controltovalida te="DropDownLis t1"
DISPLAY="Dynami c"
clientvalidatio nfunction="isIt emSelected">
</asp:CustomValid ator>
</td>
<td valign="bottom" >

<asp:Button id="DropDownBut ton"
runat="server"
Text="Button"
ONCLICK="DropDo wnButton_Click"
CAUSESVALIDATIO N="False"></asp:Button>
</td></tr>

</table>

<br><br>

<asp:label ID="Message"
RUNAT="Server"/>

</form>

</body>
</html>

----------------------CODE BEHIND------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Sub SubmitButton_Cl ick(ByVal sender As Object, ByVal e As
EventArgs)

' Determine which button was clicked.
Select Case (CType(sender, Button)).ID

Case "CityQueryButto n"

' Validate only the controls used for the city query.
CityReqValidato r.Validate()

' Take the appropriate action if the controls pass
validation.
If CityReqValidato r.IsValid Then

Message.Text = "You have chosen to run a query for
the following city: " & _
CityTextBox.Tex t

End If

Case "StateQueryButt on"

' Validate only the controls used for the state query.
StateReqValidat or.Validate()

' Take the appropriate action if the controls pass
validation.
If StateReqValidat or.IsValid Then

Message.Text = "You have chosen to run a query for
the following state: " & _
StateTextBox.Te xt

End If

Case "DropDownButton "
CustomValidator 1.Validate()

' Take the appropriate action if the controls pass
validation.
If CustomValidator 1.IsValid Then

Message.Text = "IsValid"
Else
Message.Text = "InValid"
End If

Case Else

' If the button clicked isn't recognized, erase the
message on the page.
Message.Text = ""

End Select

End Sub

Nov 19 '05 #1
1 6562
It sounds like you want "validation groups", a feature coming in the new
ASP.NET 2.0. It lets you assign a group name to each submit button and the
validators it fires. Please see this thread for details on how you to do it
without ASP.NET 2.0: http://forums.asp.net/817969/ShowPost.aspx

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlu m.com
Creator of "Profession al Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Liz" <el************ **@pigroup.co.u k> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
I have a page with several dropdownlists, several text boxes and
several buttons which perform calculations. I need to validate one
dropdownlist (not the whole page) with the click of one button. I have
a separate submit button which should validate the other fields.
This page on MSDN does what I want - almost!

http://msdn.microsoft.com/library/de...ationTopic.asp

I added a dropdownlist, customvalidator and another asp:button, but the
validation control does not work when I click on the button. (it works
when I change the value in the dropdown)
Can anyone help please?

Many thanks.

----------------------WEB FORM-----------------------------
<html>
<head>
<script LANGUAGE="javas cript">
function isItemSelected( source, arguments){
alert(source,ar guments)
if (arguments.Valu e < 1)
{
arguments.IsVal id = false;
}
else
{
arguments.IsVal id = true;
}
}
-->

</script>
</head>

<body>

<form RUNAT="server" ID="Form1">

<h3> Button CausesValidatio n Example </h3>

<table BORDER="1" CELLPADDING="10 ">
<tr>
<td>
<b>Enter city to query.</b> <br>
<asp:textbox ID="CityTextBox "
RUNAT="server"/>
<asp:requiredfi eldvalidator ID="CityReqVali dator"
CONTROLTOVALIDA TE="CityTextBox "
ERRORMESSAGE="< br>Please enter a city."
DISPLAY="Dynami c"
ENABLECLIENTSCR IPT="False"
RUNAT="server"/>
</td>
<td VALIGN="bottom" >
<asp:button ID="CityQueryBu tton"
TEXT="Submit"
CAUSESVALIDATIO N="False"
ONCLICK="Submit Button_Click"
RUNAT="server"/>
</td>
</tr>

<tr>
<td>
<b>Enter state to query.</b> <br>
<asp:textbox ID="StateTextBo x"
RUNAT="server"/>
<asp:requiredfi eldvalidator ID="StateReqVal idator"
CONTROLTOVALIDA TE="StateTextBo x"
ERRORMESSAGE="< br>Please enter a state."
DISPLAY="Dynami c"
ENABLECLIENTSCR IPT="False"
RUNAT="server"/>
</td>
<td VALIGN="bottom" >
<asp:button ID="StateQueryB utton"
TEXT="Submit"
CAUSESVALIDATIO N="False"
ONCLICK="Submit Button_Click"
RUNAT="server"/>
</td>
</tr>
<tr>
<td><asp:DropDo wnList id="DropDownLis t1" runat="server">
<asp:listitem VALUE ="0">Select</asp:listitem>
<asp:listitem VALUE ="1">UK</asp:listitem>
<asp:listitem VALUE ="2">USA</asp:listitem></asp:DropDownLis t>

<asp:CustomVali dator id="CustomValid ator1"
runat="server"
ErrorMessage="* "
controltovalida te="DropDownLis t1"
DISPLAY="Dynami c"
clientvalidatio nfunction="isIt emSelected">
</asp:CustomValid ator>
</td>
<td valign="bottom" >

<asp:Button id="DropDownBut ton"
runat="server"
Text="Button"
ONCLICK="DropDo wnButton_Click"
CAUSESVALIDATIO N="False"></asp:Button>
</td></tr>

</table>

<br><br>

<asp:label ID="Message"
RUNAT="Server"/>

</form>

</body>
</html>

----------------------CODE BEHIND------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Sub SubmitButton_Cl ick(ByVal sender As Object, ByVal e As
EventArgs)

' Determine which button was clicked.
Select Case (CType(sender, Button)).ID

Case "CityQueryButto n"

' Validate only the controls used for the city query.
CityReqValidato r.Validate()

' Take the appropriate action if the controls pass
validation.
If CityReqValidato r.IsValid Then

Message.Text = "You have chosen to run a query for
the following city: " & _
CityTextBox.Tex t

End If

Case "StateQueryButt on"

' Validate only the controls used for the state query.
StateReqValidat or.Validate()

' Take the appropriate action if the controls pass
validation.
If StateReqValidat or.IsValid Then

Message.Text = "You have chosen to run a query for
the following state: " & _
StateTextBox.Te xt

End If

Case "DropDownButton "
CustomValidator 1.Validate()

' Take the appropriate action if the controls pass
validation.
If CustomValidator 1.IsValid Then

Message.Text = "IsValid"
Else
Message.Text = "InValid"
End If

Case Else

' If the button clicked isn't recognized, erase the
message on the page.
Message.Text = ""

End Select

End Sub

Nov 19 '05 #2

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

Similar topics

2
3422
by: Brennon Arnold | last post by:
I have a problem that I figured would be relatively common, but have been unable to find any information on it as of yet. I have a page that contains two DropDownList controls, with the second being dependent on the value of the first. My DropDownList control definitions look like this: <asp:dropdownlist id="ddlLocCty" runat="server" CssClass="SmlBox" AutoPostback="True" CausesValidation="False"></asp:dropdownlist> <asp:dropdownlist...
2
8905
by: Wes Weems | last post by:
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,
4
2517
by: Keith | last post by:
I have this simple scenario. -------- Choose an item ->dropdownlist-> or <a>Create a new item</a> -------- When someone decides to click on the create a new item link, it takes them to a page in which they can enter more records to the database field to which the dropdownlist is bound.
5
2354
by: Bryan Ax | last post by:
I have a page that has two copies of the same control in it. The control is: BorrowerControl the two references to it in the page are bControl1 cobControl1
10
5320
by: Sacha Korell | last post by:
I'm trying to load a drop-down list with all DropDownList control names from another page. How would I be able to find those DropDownList controls? The FindControl method will only find a certain control by id, but I want to find all controls of a certain type (DropDownList in this case). Is there an easier way than to get a control count of the page, loop through all controls on that page, examine their type and, if they're a...
3
2927
by: Olivier Verdin | last post by:
Hi, I have a page with several Textboxes and several DropDownList. When I click on a 'save' button, it creates a record in a database. The page works fine under Internet Explorer. It does not work under FireFox. The dropdownlist are always selecting the zero index value. If I debug and I stop the program in the page_load, the dropdownlist are already set to zero index.
6
16611
by: Oscar | last post by:
I want to add items to a dropdownlist control within a Javascript eventhandler. This is what I code : var dd = document.getElementById("DropDownList1"); dd.Items.Add("1990"); dd.Items.Add("1991"); dd.Items.Add("1992");
10
6384
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code: dropdownlist.items.findbyvalue("value").selected = true I didnt specify any selected item in the dropdownlist during binding to the datasource. I use dropdownlist.clearselection() but still error occurs. I need information on this. Thanks. Ads
0
2159
by: RosH | last post by:
Hi Everyone, I have a CreateUserWizard my public sign up page of my website. I have edited the wizard to include collection of other personal information. I have a DropDownList for the selection of the Graduation year. Find the code below to Insert all the additional information to another database when a new ASP user is created. The DropDownList gets cleared of all data during execution of this code. Your thoughts on the solution...
0
8773
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
9445
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...
1
9234
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6733
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
6030
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
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.