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

<p>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.</p>

<p>I am not allowed to use an Update Panel.</p>

<p>I have build a simple demo demonstrating problem. Here is my markup code:</p>

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

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

<p>And in the code behind I have the following:</p>

<pre><code>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}&amp;query={2}",
            Request.Url.AbsolutePath,
            FilterDropDownList.SelectedValue,
            QueryTextBox.Text));
}
</code></pre>

<p>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.</p>

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