简体   繁体   English

Dropdownlist onselectedindexchanged问题

[英]Dropdownlist onselectedindexchanged problem

I have a dropdownlist like this 我有这样的下拉列表

<asp:dropdownlist runat="server" autopostback="true" onselecteditemindexchanged="fire_event" ID="DDL"/>

and on codebehind im doing this 并在代码隐藏我这样做

page_load : if(!page.postback)I m binding data into dropdownlist
   fire_event: I am redirecting page to itemselected value.

So I am able to do most of the part everything is working perfectly except.. 所以我能够完成大部分工作,除了..

when i select item in dropdown it redirects me to the page I wanted..but when i click back it remains at the same item selected value .I want it to be like that it loads again when i click back for eg 当我在下拉列表中选择项目时,它会将我重定向到我想要的页面。但是当我点击它时,它仍保留在相同的项目选择值。我希望它像是当它点击返回时再次加载例如

if my dropdown is like state A and other items 如果我的下拉状态是状态A和其他项目

A
B
C
D

when I select D it takes me to page D and when i click back it is at state D i want it to show A instead of D 当我选择D ,它将我带到页面D ,当我点击它时,它处于状态D我希望它显示A而不是D

When you use the back button on many(though not necessarily all) browsers you are not hitting the server, you are retrieving a copy of the page that has been cached by the browser in it's last state. 当您在许多(但不一定是所有)浏览器上使用后退按钮时,您没有访问服务器,而是检索浏览器在其最后状态下缓存的页面副本。
To avoid this you will need to prevent your page from being cached so that it is retrieved from the server instead. 为避免这种情况,您需要阻止页面被缓存,以便从服务器中检索它。 Adding the following to your page load will certainly do the trick in IE. 将以下内容添加到页面加载中肯定会在IE中完成。 Further investigation has revealed that this can also be achieved in Firefox using the no-store attribute: 进一步调查显示,这也可以使用no-store属性在Firefox中实现:

    Response.CacheControl = "no-cache";
    Response.Cache.SetNoStore();
    Response.AddHeader("Pragma", "no-cache");
    Response.Expires = -1;

You can use javascript to ensure that the right value is selected when the document is loaded. 您可以使用javascript确保在加载文档时选择正确的值。 The following code is with jquery but you can do the same with Microsoft Ajax... 以下代码使用jquery,但您可以使用Microsoft Ajax执行相同操作...

$.ready(function() {
    $("#mySelect").val(''); // Set the default value to select here
});

Have a good day! 祝你有美好的一天!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM