我得的DropDownList在UpdatePanel中,如下圖所示:的DropDownList的SelectedIndex不能在Firefox工作頁面刷新後
<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>
在我隱藏我有了這個簡單的代碼:
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();
}
這裏是問題:我在列表中選擇了大於0的某個項目(例如5),標籤顯示的值爲5.但是,當我刷新頁面時,通過點擊Firefox中的刷新按鈕,標籤顯示值0(因爲它應該是)但下拉列表顯示5.我檢查了頁面html源代碼,並且下拉列表選擇了值0 ,但顯示爲5.但是,當我通過將光標放在地址欄中並按Enter時,每個工作都正常(刷新顯示0),刷新頁面。這個問題只發生在FireFox中(我有3.5.7版本)。
任何想法可以導致這個問題?
謝謝詹姆斯,是解決我的問題。 – jartur 2010-04-20 11:09:48