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 360301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:28:34+00:00 2026-05-12T12:28:34+00:00

I have the following on my website. Source [DropDownList] Website Search Engine Other Other

  • 0

I have the following on my website.

Source [DropDownList]

Website

Search Engine

Other

Other Source [TextBox]

I want to use the ASP.Net validators (I think the compare validator) so that when “Other” is selected in the dropdownlist and no text is entered the validation is triggered and the page cannot be submitted.

Is this possible?

Ive tried to set the value of the “Other” option in the drop down to string.empty and compare it to an empty text box but this didn’t work.

The whole thing that I have inherited is inside a wizard control, otherwise I would hook up some client script to trigger the validation myself. I don’t think I can do this with a wizard control?

Thanks in advance.

  • 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-12T12:28:34+00:00Added an answer on May 12, 2026 at 12:28 pm

    None of the ASP.NET provided validators allow you to perform conditional validation based on another control. However, you can achieve this by using a CustomValidator that performs validation on the client-side, server-side, or both (at a minimum, server-side validation is recommended). The validators work well in conjunction with wizards.

    ASP.NET markup example:

        <asp:DropDownList ID="OptionsDropDownList" runat="server">
            <asp:ListItem Text="Website" />
            <asp:ListItem Text="Search Engine" />
            <asp:ListItem Text="Other" />
        </asp:DropDownList>
        <asp:TextBox ID="OtherTextBox" runat="server" />
        <asp:CustomValidator ID="custvOptionsDropDownList" runat="server" ControlToValidate="OptionsDropDownList"
            ValidateEmptyText="true" Display="Dynamic" ClientValidationFunction="validateOtherTextBox"
            ErrorMessage="This field is required!" OnServerValidate="ValidateOtherTextBox" />
    

    Javascript for ClientValidationFunction:

    <script type="text/javascript" language="javascript">
        function validateOtherTextBox(event, args) {
            var textbox = document.getElementById('<%= OtherTextBox.ClientID %>').value;
            if (args.Value == 'Other')
                args.IsValid = (textbox != '');
            else
                args.IsValid = true;
        }
    </script>
    

    Code-Behind for OnServerValidate:

        protected void ValidateOtherTextBox(object source, ServerValidateEventArgs args)
        {
            if (OptionsDropDownList.SelectedValue == "Other")
            {
                args.IsValid = (OtherTextBox.Text.Trim() != "");
            }
        }
    

    Note that it’s your choice to implement whatever you need. You could completely skip Javascript validation and remove that code and the ClientValidationFunction attribute. Also, notice that the Javascript refers to the target control by using the ClientID property. This is needed since ASP.NET assigns a different ID when the page is output and you’ll want it to be provided to the Javascript method in this manner (view source on the page and you’ll see that the control name has an extra prefix etc.).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following view definition in my asp.net mvc website: <% Using Ajax.BeginForm(UsrCtlChangePassword,
I have been following the tutorial on Microsofts website and they use GameTime to
Hi I have the following problem, I want to laod a website with php.
i have the following situation, i have a Reporting layer(stand alone) in asp.net application(NOT
I have been trying to read the source of a website with the following:
I have created a website using asp.net and I have created some resource files
all I have downloaded source code from google android website following google's guide. My
I'm learning C# and working on my first ASP.Net e-commerce website. I have the
Let's say I have the following within my source code, and I want to
I want to have an ASP C# WebSite that loads a simple CSV File

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.