Note that there are some explanatory texts on larger screens.

plurals
  1. POSetting DropDownList Server Control Using jQuery Doesn't Change SelectedValue
    text
    copied!<p>I am running into an issue where I set the value of a dropdownlist (asp.net server control) using jQuery, but it doesn't change the selectedvalue upon postback. The control is not databound, so I don't believe the issue has anything to do with the change being overwritten. The control is inside a WizardControl, which I also don't think has anything to do with the issue. On the client side everything works as expected.</p> <p>Here is my code:</p> <pre><code>&lt;asp:DropDownList runat="server" ID="MilitaryBackgroundSelect" ClientIDMode="Static"&gt; &lt;asp:ListItem Text="" Value="" Selected="True" /&gt; &lt;asp:ListItem Text="No" Value="0" /&gt; &lt;asp:ListItem Text="YES, IN THE ARMED FORCES" Value="1" /&gt; &lt;asp:ListItem Text="YES, IN THE RESERVES" Value="2" /&gt; &lt;asp:ListItem Text="YES, IN THE NATIONAL GUARD" Value="3" /&gt; &lt;asp:ListItem Text="REFUSED" Value="-7" /&gt; &lt;asp:ListItem Text="DON'T KNOW" Value="-8" /&gt; &lt;asp:ListItem Text="MISSING DATA" Value="-9" /&gt; &lt;/asp:DropDownList&gt; </code></pre> <p>I am setting the dropdownlist on the client side using this code:</p> <pre><code> $(document).ready(function(){ $('#MilitaryBackgroundSelect').val("1"); }); </code></pre> <p>NOTE: I set the clientidmode to static on the dropdownlist, so I have no issue interacting with it using jQuery. Below is the HTML rendered, notice the id field:</p> <pre><code>&lt;select name="ctl00$ctl00$MainContent$MainContentNested$AHHQ_DataEntryWizard$MilitaryBackgroundSelect" id="MilitaryBackgroundSelect"&gt; &lt;option value=""&gt;&lt;/option&gt; &lt;option selected="selected" value="0"&gt;No&lt;/option&gt; &lt;option value="1"&gt;YES, IN THE ARMED FORCES&lt;/option&gt; &lt;option value="2"&gt;YES, IN THE RESERVES&lt;/option&gt; &lt;option value="3"&gt;YES, IN THE NATIONAL GUARD&lt;/option&gt; &lt;option value="-7"&gt;REFUSED&lt;/option&gt; &lt;option value="-8"&gt;DON&amp;#39;T KNOW&lt;/option&gt; &lt;option value="-9"&gt;MISSING DATA&lt;/option&gt; &lt;/select&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload