The selectedindex drop-down list does not work when refreshing the page.

I have a problem with a very normal ASP.NET dropdown. I have a dropdown on page c AutoPostback=false. And the code for creating the dropdownlists content:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        this.dropDownList.Items.Add(new ListItem("text1", "value1"));
        this.dropDownList.Items.Add(new ListItem("text2", "value2"));
        this.dropDownList.SelectedIndex = 0;
    }
}
  • Launch the page and select the second option: text2.
  • After that, press F5, this will load the page (note that I have not done the postback yet, just change the selected Dropdownlist item and press F5)

I expected the dropdown to now select the default item with index = 0, but the selected item is still the "text2" element - the item I selected. In this situation this.dropDownList.SelectedIndex = 0;does not work.

I totally don't understand. Can anyone help me?

: Firefox, Chrome/IE.

+5
2

, , post back; . F5 , , Page.IsPostBack false.

, asp:Button ( AutoPostBack=true DropDownList).


, Firefox - , , F5. , select .

<script type='text/javascript'>
    document.getElementById('<%= dropDownList.ClientID %>').selectedIndex = 0;
</script>

(: , .)

+2

F5, .
, . .

URL enter ; . SelectedIndex 0.

+1

All Articles