<p>I have a weird problem with a dropdownbox selectedIndex always being set to 0 upon postback. I'm not accidentally rebinding it in my code. In fact I've placed a breakpoint at the very first line of the page_load event and the value is already set to zero. The dropdown is in the master page of my project, I don't know if that makes a difference. I'm not referencing the control in my content holder. </p>

<p>If I set my autoPostBack = 'true' the page works fine. I don't have to change any code and the selectedIndex is maintained. I have also tried setting enableViewState on and off and it doesn't make a difference. At this point I'm grasping at straws to figure out what's going on. I've never had this problem before.</p>

<p>Here is the code in my page_load event.</p>

<pre><code>        If CartEstablished Then
            txtCustNum.Visible = False
            btnCustSearch.Visible = False
            lblCustNum.Visible = True
            ddlSalesType.Visible = False
            lblSalesType.Visible = True
            ddlTerms.Visible = False
            lblTerms.Visible = True

            lblTerms.Text = TermsDescription
        Else
            txtCustNum.Visible = True
            btnCustSearch.Visible = True
            lblCustNum.Visible = False

            lblSalesType.Visible = False
            ddlSalesType.Visible = True
            lblTerms.Visible = False
            ddlTerms.Visible = True
        End If

        If Page.IsPostBack Then
             GetUIValues()
        Else

             LoadTermCodes()
        End If
</code></pre>

<p>The LoadTermCodes is where I bind the dropdownlist that is causing me problems.</p>

[{'answer_id': 73501, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': 1, 'selected': False, 'text': '<p>Are you sure you are doing a postback and not a refresh? It is hard to help you without more context into the problem or a chunk of the code.</p>\n'}, {'answer_id': 73543, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>This may be barking up the wrong tree, but a couple of things that have bitten me in the past that left me scratching my head:</p>\n\n<ul>\n<li>Naming the input element a duplicated/reserved word (thinking "name", "method", "reset", etc.)</li>\n<li>having the form element physically outside of the form being submitted</li>\n</ul>\n\n<p>I find that when all the logical debugging turns up nothing, my own dumbness has created time-wasting "mystery" bugs like this on occasion.</p>\n'}, {'answer_id': 73627, 'author': 'derek lawless', 'author_id': 400464, 'author_profile': 'https://Stackoverflow.com/users/400464', 'pm_score': 0, 'selected': False, 'text': "<p>At what stage in the page lifecycle are you binding the dropdownlist? If you're binding in page_init it should work, if you're binding in page_load make sure you wrap a !IsPostBack around the binding commands.</p>\n\n<p>If you post the code in question it'd be easier to troubleshoot.</p>\n"}, {'answer_id': 74783, 'author': 'Gilligan', 'author_id': 12356, 'author_profile': 'https://Stackoverflow.com/users/12356', 'pm_score': -1, 'selected': False, 'text': "<p>This may simply be a syntax error, but shouldn't</p>\n\n<pre><code> If Page.IsPostBack Then\n             GetUIValues()\n        Else\n</code></pre>\n\n<p>Look like this</p>\n\n<pre><code>  If  NOT Page.IsPostBack Then\n         GetUIValues()\n    Else\n</code></pre>\n"}, {'answer_id': 264776, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>I'm finding the same problem... in my case, the dropdownlist is filled by a javascript function after another dropdownlist onchange client event. On PageLoad, the 2nd dropdownlist has lost all its items and so its selectedIndex turns to 0. Is there any way of preventing this?</p>\n"}]
['https://Stackoverflow.com/questions/73456', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/288/']