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

  • Home
  • SEARCH
  • 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 8216933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:18:16+00:00 2026-06-07T12:18:16+00:00

On my page I have a text box that uses a custom validator: <asp:CustomValidator

  • 0

On my page I have a text box that uses a custom validator:

<asp:CustomValidator ID="cv_Question" ControlToValidate="tb_Question" runat="server" ErrorMessage="*" OnServerValidate="ValidateQuestion" ClientValidationFunction="CheckQuestion" ForeColor="#FF0000" ValidationGroup="CreateUser"></asp:CustomValidator>

The client side validation script that I would like to use always returns 0 for the drop down list SelectedValue, even when the drop down list index has already changed.

I set the drop down list default index to 0 with !Page.IsPostBack

Here is the drop down list:

<asp:DropDownList ID="ddl_Question" runat="server" EnableViewState="true" AutoPostBack="true" onselectedindexchanged="ddl_Question_SelectedIndexChanged">
        <asp:ListItem Selected="False" Text="Select a question" Value="0"></asp:ListItem>
        <asp:ListItem Selected="False" Text="What was the first movie I ever saw?" Value="1"></asp:ListItem>        
        <asp:ListItem Selected="False" Text="What is the middle name of my oldest child?" Value="2"></asp:ListItem>
        <asp:ListItem Selected="False" Text="In what city was my father born?" Value="3"></asp:ListItem>
        <asp:ListItem Selected="False" Text="Who was my favourite cartoon character as a child?" Value="4"></asp:ListItem>
        <asp:ListItem Selected="False" Text="What is my mother's middle name?" Value="5"></asp:ListItem>
        <asp:ListItem Selected="False" Text="In what year did I meet my significant other?" Value="6"></asp:ListItem>
        <asp:ListItem Selected="False" Text="What was my first pet's name?" Value="7"></asp:ListItem>
        <asp:ListItem Selected="False" Text="First name of the maid of honour at my wedding?" Value="8"></asp:ListItem>
        <asp:ListItem Selected="False" Text="First name of my best friend in elementary school?" Value="9"></asp:ListItem>
        <asp:ListItem Selected="False" Text="Name of my all-time favourite movie character?" Value="10"></asp:ListItem>
        <asp:ListItem Selected="False" Text="Create a question" Value="11"></asp:ListItem>
    </asp:DropDownList>

Here is the client side validation:

   <script type="text/javascript" language="javascript">
        function CheckQuestion(sender, args) 
        {        
            var Question =  args.Value.toString();

            <% if(Convert.ToInt32(ddl_Question.SelectedValue) == 11) 
            { %>
                if (Question != "" && Question != null) 
                {
                    args.IsValid = true;
                    return;
                }
                else
                {
                    args.IsValid = false;
                    return;
                }
            <% } 
            else
            { %>
                alert(<%= Convert.ToInt32(ddl_Question.SelectedValue)%>);
                args.IsValid = true;
                return;
            <% } %>
        }
    </script>

I only want to validate the tb_Question if the user has selected “Create a question” from the ddl_Question.

EDIT:

Here is my SelectedIndexChanged method. The tb_Question is made visible when the user selects “Create a question”. This happens before any validation occurs.

protected void ddl_Question_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (Convert.ToInt32(ddl_Question.SelectedValue) == 11)
        {
            Question.Visible = true;
        }
        else
        {
            Question.Visible = false;
        }
    }
  • 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-06-07T12:18:17+00:00Added an answer on June 7, 2026 at 12:18 pm

    Well my recommendation is to use simple JavaScript

    So instead of doing that, use JavaScript and maybe jQuery like this

    jQuery Nuget: https://nuget.org/packages/jQuery

    <script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" language="javascript">
        function CheckQuestion(sender, args) 
        {        
            var Question =  args.Value.toString();
            var questionID = '<%= this.ddl_Question.ClientID %>';
            var currentQuestion = $("#" + questionID).val();
    
            if (currentQuestion == '11')
            { 
                if (Question != "" && Question != null) 
                {
                    args.IsValid = true;
                    return;
                }
                else
                {
                    args.IsValid = false;
                    return;
                }
            } 
            else
            {
                alert(currentQuestion);
                args.IsValid = true;
                return;
            }
        }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP page which displays a text box when it loads. It
I have information entered into a text box on an ASP.net 3.5 page. when
I have a text box that the contents change on page reload, but what
I have an issue with the following text display: <asp:RegularExpressionValidator ID=Password_RegularExpValidate runat=server Text=TEST! Display=Dynamic
I have a ASP.NET web page that contains many textboxes. Each textbox has a
I have a text box on a web page, whose value I want to
I want to be able to have a text box on a page where
I have a web page with a read-only text box which shows some HTML
I have a simple page. One Rich Text Box bound to a test table
I have this html page which is very simple, it contains a text box

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.