【问题标题】:back button on browser is postback?浏览器上的后退按钮是回发?
【发布时间】:2016-08-13 09:19:02
【问题描述】:

我有一个网站http://www.dendy.com.au/Page/Home,在下拉框中有 2 个选项,它通过获取cinemaid cookie 来加载会话数据(newtown),这很好。当我更改选项时,它会加载其他影院会话数据。

问题是当我加载第二个会话数据(Opera Quays)并点击一部电影然后按回浏览器(大多数人是如何做的)时,由于 cookie,它会再次使用 Newtown 数据加载主页,但在即使在检查元素 Newtown 选项中选择了值,它仍然选择了 Qpera Quay。

我怀疑这是由于页面缓存造成的。所以它会选择我之前选择的下拉选项,但会从 cookie 中加载 newtown 的会话数据。

如果有办法解决它? 这是我的代码

 protected void Page_Load(object sender, EventArgs e)
{
    // get cinemaid  from  cookie in the usercontrol base class 
    IList<ORM.Cinema> cinemaList = DAL.DataClasses.CinemaGroup.GetCinemasInGroupByCinemaId(cinemaId);
    //if there's only 1 cinema, hide the cinema selection area
    if (cinemaList.Count() == 1)
    {
        SelectCinemaDiv.Visible = false;
    }
    else
    {
        //set the default cinema dropdownlist selection
        CinemaDropDownList.DataSource = cinemaList;
        CinemaDropDownList.DataBind();
        CinemaDropDownList.SelectedValue = cinemaId.ToString();
        cinemaId = new Guid(CinemaDropDownList.SelectedValue);
    }

        //loads sessions data
    SessionTimeLiteral.Text = LoadCinemaSessionsDirect.LoadCinemaSessionsForOneCinema(cinemaId.ToString(), thisInstance.IncludeElementInstanceId.ToString());

我尝试使用 !Postback 但没有成功

//if there's only 1 cinema, hide the cinema selection area
    if (!IsPostBack)
    {
        if (cinemaList.Count() == 1)
        {
            SelectCinemaDiv.Visible = false;
        }
        else
        {


            //set the default cinema dropdownlist selection
            CinemaDropDownList.DataSource = cinemaList;
            CinemaDropDownList.DataBind();
            CinemaDropDownList.SelectedValue = cinemaId.ToString();
        }
    }
    else
    {
        cinemaId = new Guid(CinemaDropDownList.SelectedValue);
    }

【问题讨论】:

  • 这不是真正的缓存,而是视图状态。尝试禁用相关控件的视图状态:&lt;asp:DropDownList ID="CinemaDropDownList" runat="server" EnabledViewState="false" /&gt;。如果这行得通,很好。如果没有,那么,值得一试。 :)
  • 谢谢,不幸的是这没用...

标签: jquery asp.net cookies drop-down-menu postback


【解决方案1】:

为什么不使用 Session 变量来存储用户选择的内容?然后在页面加载中的所有页面上,您可以通过检查会话数据来交换它?

Session["UserSelection"] = CinemaDropDownList.SelectedValue;

【讨论】:

  • 我尝试使用会话,但没有运气。当用户按下浏览器时。它加载上一页的缓存并且从不回击服务器(不命中页面加载方法)
  • @user3060334 这更像是一个错误,还是您的应用程序的流程取决于使用后退按钮的用户?您可以使用一些 javascript 技巧来尝试扼杀后退按钮
  • 我考虑过在 windows.history.forward() 有值时强制刷新页面,但您无法检查是否有任何其他 js 建议的值?
猜你喜欢
  • 2013-03-02
  • 2010-11-17
  • 2012-07-09
  • 1970-01-01
  • 2011-02-17
  • 1970-01-01
  • 2022-01-07
  • 2018-07-11
  • 2016-02-20
相关资源
最近更新 更多