gpt4 book ai didi

firefox - 页面刷新后 DropDownList SelectedIndex 在 FireFox 中不起作用

转载 作者:行者123 更新时间:2023-12-02 21:14:10 25 4
gpt4 key购买 nike

我在 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 (正如它应该的那样)但下拉列表显示 5。我检查了页面 html 源,下拉列表选择了值 0,但显示 5。但是,当我通过将光标放在地址栏中并按 Enter 刷新页面时,一切正常(drowdownlist显示 0)。该问题仅出现在 FireFox 中(我的版本是 3.5.7)。

有什么想法会导致这个问题吗?

最佳答案

Firefox 会记住 session 中每个选择的 selectedIndex。这对用户来说有好处,但对开发人员来说却很麻烦......我也遇到了同样的问题。如果我找到解决方案,我会发布它。

看看这个: https://developer.mozilla.org/en/Using_Firefox_1.5_caching

它有效!

在 PHP 中:

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

关于firefox - 页面刷新后 DropDownList SelectedIndex 在 FireFox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2545840/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com