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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:17:32+00:00 2026-05-26T20:17:32+00:00

How do I read the SelectedValue of a DropDownList in code behind, when the

  • 0

How do I read the SelectedValue of a DropDownList in code behind, when the option has been added using JavaScript?

A little more background: I have cascading drop down lists, and I would like to fill in the values using JavaScript, so that I avoid postbacks when the user changes the selection in the first drop down list.

I am not allowed to use an Update Panel.

I have build a simple demo demonstrating problem. Here is my markup code:

<p>
    <asp:DropDownList runat="server" ID="FilterDropDownList" />
</p>
<p>
    <asp:Button runat="server" ID="SearchButton" Text="Search" 
        onclick="SearchButton_Click" /><br/>
    <asp:TextBox runat="server" ID="QueryTextBox" />
</p>
<script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        var filterDropDownListId = '#<%= FilterDropDownList.ClientID %>';

        $(filterDropDownListId).append($('<option>').prop('value', 'Alpha').html('A'));
        $(filterDropDownListId).append($('<option>').prop('value', 'Beta').html('B'));
    });
</script>

And in the code behind I have the following:

protected override void Render(HtmlTextWriter writer)
{
    // Register the allowed values for the down down list.
    Page.ClientScript.RegisterForEventValidation(FilterDropDownList.UniqueID, "Alpha");
    Page.ClientScript.RegisterForEventValidation(FilterDropDownList.UniqueID, "Beta");

    base.Render(writer);
}

protected void SearchButton_Click(object sender, EventArgs e)
{
    Response.Redirect(
        String.Format("{0}?dropdown={1}&query={2}",
            Request.Url.AbsolutePath,
            FilterDropDownList.SelectedValue,
            QueryTextBox.Text));
}

The problem is, that FilterDropDownList.SelectedValue is empty. I would have expected it to be either “Alpha” or “Beta”. I can read the value of QueryTextBox.Text without problems.

It is possible to read MyDropDownList.SelectedValue when the values have been populated using JavaScript? Or do a have to use a different approach?

  • 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-26T20:17:33+00:00Added an answer on May 26, 2026 at 8:17 pm

    You can always write the selected value to a hidden textbox with javascript and read the value in the code-behind.

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

Sidebar

Related Questions

I have the following code that sets a cookie: string locale = ((DropDownList)this.LoginUser.FindControl(locale)).SelectedValue; HttpCookie
I am using ASP.NET forms version 3.5 in VB I have a dropdownlist that
Ok guys, so I read this: How to set SelectedValue of DropDownList in GridView
I read in this article that a company has created a software capable of
I have the following code in my codebehind Page_Load function that sets the default
I'm creating a drop down via <%= Html.DropDownList(data.Language, Model.LanguageOptions) %> and want to read
Using C# & Mysql I have combobox & button in my webpage, if i
I have two problems that I'm not sure are related: I have two DropDownList
I am using javascript to validate user input on my aspx page. I am
I have been asked to make some customisation changes to our Dynamics CRM 4.0

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.