Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:56:01+00:00 2026-05-29T20:56:01+00:00

I need to validate TextBox based on Value selected in DropDownList controls. I have

  • 0

I need to validate TextBox based on Value selected in DropDownList controls. I have asp:TextBox and asp:DropDownList controls.

If user selects Yes option from the first dropdown he must type value in text box. How can I validate second box? Thanks for help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:56:04+00:00Added an answer on May 29, 2026 at 8:56 pm

    The simplest approach is to set the DropDownList’s AutoPostBack property to true and handle it’s SelectedIndexChanged event. Then you can Enable/Disable the validator there.

    Another approach is to use a CustomValidator. This validator is not dependent on a single control. You must write the validation rules on your own. For example the ClientValidationFunction:

    <script type="text/javascript" >
        function ClientValidate(source, arguments) {
            var txt = document.getElementById('TextBox1');
            var ddl = document.getElementById('DropDownList1');
            var decision = ddl.options[ddl.selectedIndex].text;
            if(decision=='Yes'){
                arguments.IsValid = txt.value.length > 0;
            }else{
                arguments.IsValid = true;
            }
        }
    </script>
    
    <asp:DropDownList id="DropDownList1" runat="server">
        <asp:ListItem Selected="True">Yes</asp:ListItem>
        <asp:ListItem Selected="False">No</asp:ListItem>
    </asp:DropDownList>
    <asp:TextBox id="TextBox1" runat="server" />
    <asp:Button ID="BtnSubmit" runat="server" Text="Submit" />
    
    <asp:CustomValidator id="CustomValidator1"
           ValidateEmptyText="true"
           ControlToValidate="TextBox1"
           ClientValidationFunction="ClientValidate"
           OnServerValidate="ServerValidation"
           Display="Static"
           ErrorMessage="Please enter text!"
           runat="server"/>
    

    Remember to always implement a OnServerValidate because you should not rely on javascript only(can be disabled). This is easy:

    void ServerValidation(object source, ServerValidateEventArgs args){
        args.IsValid = DropDownList1.SelectedIndex == 1 || TextBox1.Text.Length > 0;
    }
    

    VB.NET

    Protected Sub ServerValidation(source As Object, args As System.Web.UI.WebControls.ServerValidateEventArgs)
        args.IsValid = DropDownList1.SelectedIndex = 1 OrElse TextBox1.Text.Length > 0
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom control with asp textbox inside. And i need to Validate by
I need to validate a textbox as follows: When the user changes focus from
I have a RadioButtonList and based on what is selected I need a TextBox
I need to validate this simple pick list: <select name=<%= key %>> <option value=ETC
I have a few section in an ASP.NET page and need to validate them
I need to validate Textbox input as credit card number. I already have regex
I need to validate a textbox, so it's value consist of 10 characters (not
I need to validate a number entered by a user in a textbox using
I need to validate various ASP.NET controls, but instead of displaying the standard text/asterisk/image
I have a text box I need to validate that.. I mean user can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.