Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Required field validation based on Drop-down value

Status
Not open for further replies.

boatdrinks

IS-IT--Management
Jun 18, 2004
51
US
I have a drop-down box and a textbox. I would like to set the validator of the textbox to require a value only if a specific value is selected in the drop-down. So far this is what I have done, and it does not work. I would like to do this in VB also.

This is in the page_Load


If inserthardware.selectedvalue = "Classroom" then
barcodevalidator.ControlToValidate="insertbarcode"
end if


This is the drop-down in the body of the page

<asp:DropDownList id="inserthardware" width="175" runat="server">
<asp:ListItem value="somethingelse" text="somethingelse"/>
<asp:ListItem value="Classroom" text="Classroom"/>

This is the text box in the body of the page

<asp:Textbox id="Insertbarcode" width="175" runat="server" />

<asp:RequiredFieldValidator id="barcodevalidator" Text="*" ErrorMessage="Barcode" runat="server" />


Please Help
 
I think that you want this code:

If inserthardware.SelectedItem.Value = "Classroom" then
barcodevalidator.ControlToValidate="insertbarcode"
end if

In the OnClick event of a button...Not in the Page_Load().


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top