【发布时间】: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);
}
【问题讨论】:
-
这不是真正的缓存,而是视图状态。尝试禁用相关控件的视图状态:
<asp:DropDownList ID="CinemaDropDownList" runat="server" EnabledViewState="false" />。如果这行得通,很好。如果没有,那么,值得一试。 :) -
谢谢,不幸的是这没用...
标签: jquery asp.net cookies drop-down-menu postback