views:

355

answers:

1

I've got DropDownList in 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 codebehind i've 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 in the list some item grater than 0 e.g. 5, the label shows value 5. But when I refresh the page, by hitting the refresh button in firefox, the label shows value 0 (as it's supposed to) but the dropdownlist shows 5. I checked the page html source and the dropdown has selected value 0, but shows 5. However, When I refresh the page by putting cursor in address bar and press enter everythig works fine (drowdownlist shows 0). The problem occurs only in FireFox (I've got version 3.5.7).

Any ideas what can cause this problem?

+1  A: 

Firefox remembers the selectedIndex of each select in a session. It's good for a user but it's a hassle for developers... I'm having the same problem. If I find a solution I'll post it.

Check this out: https://developer.mozilla.org/en/Using_Firefox_1.5_caching

It works!

In PHP:

James
Thank you James, that solved my problem.
jartur