DropDownList SelectedIndex not working in FireFox after page refresh

I have a DropDownList in an UpdatePanel as shown below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:DropDownList ID="DropDownList1" runat="server">
            </asp:DropDownList>
            <div>
                Index: <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

In my code, I got this simple code:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillDropDownList();
        }
    }

    private void FillDropDownList()
    {
        for (int i = 0; i < 10; i++)
        {
            DropDownList1.Items.Add(new ListItem(i.ToString(), i.ToString()));
        }
        DropDownList1.SelectedIndex = 0;

        Label1.Text = DropDownList1.SelectedIndex.ToString();
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = DropDownList1.SelectedIndex.ToString();
    }

Here is the problem: I select some element in the list that is greater than 0 (for example, 5), the label shows the value 5. But when I refresh the page by clicking the refresh button in firefox, the label shows the value 0 (as expected), but in the drop-down list shown 5. I checked the source of the html page and the dropdown menu selected 0 but shows 5. However, when I refresh the page by placing the cursor in the address bar and pressing enter, each one works fine (drowdownlist shows 0). The problem only occurs in FireFox (I have version 3.5.7).

Any ideas what might cause this problem?

+3
3

Firefox selectedIndex . , ... . , .

: https://developer.mozilla.org/en/Using_Firefox_1.5_caching

!

PHP:

<?
    header("cache-control: no-store");
    header("Pragma: no-cache");
?>
+3

autocomplete off, Firefox. .

.

<form id="myForm" action="/submithandler/" method="get" autocomplete="off">
...
</form>

, (X) HTML, , jQuery:

$("#myForm").attr("autocomplete", "off");
+1

For those facing this "Back-Forward-Cache" issue , this blogpost really enlightened the issue for me.

0
source

Source: https://habr.com/ru/post/1739151/


All Articles