我有一个启用了自动回发的 asp.net Dropdownlist。它不是动态填充的,它的值在 HTML 代码中是固定的:
<asp:dropdownlist id="ddlReportView" runat="server" autopostback="True" onselectedindexchanged="ddlReportView_SelectedIndexChanged" enableviewstate="true">
<asp:listitem text="Snapshot" value="SNAPSHOT"></asp:listitem>
<asp:listitem text="Detailled" value="DETAILLED"></asp:listitem>
<asp:listitem text="Review" value="REVIEW"></asp:listitem>
<asp:listitem text="Review Summary" value="REVIEW_SUMMARY"></asp:listitem>
</asp:dropdownlist>
如果我选择一个项目,它会重新加载页面以显示不同格式的列表。我的问题是,当我单击后退浏览器按钮时,下拉列表的值仍然是最后选择的值。
示例:
起初列表处于快照模式: alt text http://img44.imageshack.us/img44/3749/37948756.png
然后用户点击查看摘要模式: alt text http://img36.imageshack.us/img36/545/96184426.png
页面现在显示评论摘要网格,一切正常: alt text http://img17.imageshack.us/img17/8239/13194229.png
用户按下后退按钮,网格以快照模式显示(这没问题),但是 下拉列表仍然显示“评论摘要”! alt text http://img190.imageshack.us/img190/6747/22053199.png
我尝试使用 javascript 设置 select 的值,但它不起作用。有没有人遇到过这个问题,或者知道如何解决这个问题?
谢谢。
最佳答案
我设法让 javascript 使用 jQuery 来处理这个......
$(document).ready(function() {
//Reset drop down list
$("#<%= dropDownList1.ClientID %> > option:first").attr("selected", "selected");
});
或者如果初始值应该是 'SNAPSHOT' 选项...
$(document).ready(function() {
$("#<%= dropDownList1.ClientID %>").val("SNAPSHOT");
});
关于c# - ASP.NET DropdownList autopostback 和浏览器后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1235841/