ASP.NET-浏览器返回按钮时DropDownList包含错误的值
我在数据列表中有这个下拉列表ASP.NET-浏览器返回按钮时DropDownList包含错误的值,asp.net,drop-down-menu,Asp.net,Drop Down Menu,我在数据列表中有这个下拉列表 <asp:DropDownList runat="server" ID="DDL_ProdCat" OnSelectedIndexChanged="DDL_ProdCat_SelectedIndexChanged" Autopostback="true" DataTextField="Name" DataValueField="ID" /> 当用户在此下拉列表中进行选择时,对于某些选择,它们将被重定向到单独的页
<asp:DropDownList runat="server" ID="DDL_ProdCat" OnSelectedIndexChanged="DDL_ProdCat_SelectedIndexChanged"
Autopostback="true" DataTextField="Name" DataValueField="ID" />
当用户在此下拉列表中进行选择时,对于某些选择,它们将被重定向到单独的页面
在被重定向后,用户点击浏览器返回按钮,他们将返回到带有DropDownList的页面
不幸的是,将他们重定向到新页面的选项仍然处于选中状态
示例
- DDL包含A,B——初始选定值:A
- 用户选择B——回发将它们重定向到另一个页面
- 用户点击浏览器上的“后退”
- 页面现在显示“B”为选中状态,而页面状态建议仍应选择“A”。页面永远不能处于“B”状态,因为“B”被标记为将用户重定向到另一个页面李>
- 我被迫在这里使用DDL,因为常见的情况是不发生重定向。我知道这通常不是将用户链接到其他页面的最佳选择
- 不幸的是,由于性能原因,我无法关闭整个页面的浏览器缓存
Response.Expires = 0
Response.Cache.SetNoStore()
Response.AppendHeader("Pragma", "no-cache")
按照建议,在页面上使用JavaScript重新设置下拉列表中的选择。以下是适用于我的代码:
<script type="text/javascript">
window.onload = function () {
var ControlValue = document.getElementById("<%= DropDownList.ClientID %>");
if (ControlValue.value != origControlValue) {
ControlValue.value = origControlValue;
}
}
var origControlValue = document
.getElementById("<%= DropDownList.ClientID %>").value;
</script>
window.onload=函数(){
var ControlValue=document.getElementById(“”);
if(ControlValue.value!=origControlValue){
ControlValue.value=原始控制值;
}
}
var origControlValue=文档
.getElementById(“”)值;
可能是一个客户端脚本,用于在到达时通过“后退”按钮重置DDL选择?哦,没有注意到您无法关闭缓存。那就不管了。这和Response.Cache.SetCacheability(HttpCacheability.NoCache)有什么区别?谢谢Paul的建议,我在最初的问题中不清楚页面级别caching@James,Response.Cache.SetCacheability(HttpCacheability.NoCache)我相信只适用于IE@hamlin11您可以在第2页中设置一个会话布尔值,该值设置为true,如果用户返回到第1页,则在if语句中使用该布尔值来取消选择ddl。