我在 UpdatePanel 中有 DropDownList,如下所示:
<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(因为它应该to)但下拉列表显示 5。我检查了页面 html 源,下拉列表选择了值 0,但显示 5。但是,当我通过将光标放在地址栏中并按 Enter 刷新页面时,一切正常(下拉列表显示 0) . 该问题仅在 FireFox 中出现(我有 3.5.7 版)。
有什么想法会导致这个问题吗?