我有一些下拉菜单供您选择日期。问题是选择日期后,用户需要登录。此后,刷新选择日期的所有成员日期会话都丢失了(不仅是js,而且由于相关的选择,很多日期到来了。>
我试图将选定的项目保存在cookie中,但是没有用。
我有索引的会话
private int getIndexFromSession()
{
int index = 0;
if (Session["DTF_selectedIndex"] != null)
{
index = (int)Session["DTF_selectedIndex"];
// Session.Remove("DTF_selectedIndex");
if (index > dateTimeFilter.Items.Count)
index = 0;
}
return index;
}
.aspx中的下拉列表:
<asp:DropDownList ID="dateTimeFilter" runat="server" OnSelectedIndexChanged="dateTimeFilter_SelectedIndexChanged"
和.cs
protected void dateTimeFilter_SelectedIndexChanged(object sender, EventArgs e)
{
// showsDatalistPanel.Visible = true;
DropDownList ddl = (DropDownList)sender;
if (ddl.SelectedValue != "0")
{
Session["DTF_selectedIndex"] = ddl.SelectedValue;
HttpCookie cookie = new HttpCookie("DTF_selectedIndex", ddl.SelectedValue);
DateTime now = DateTime.Now;
cookie.Expires = now.AddMinutes(10);
Response.Cookies.Add(cookie);
}
}
和请求
protected void Page_Load(object sender, EventArgs e)
{
if (Session["DTF_selectedIndex"] != null)
{
Session["DTF_selectedIndex"] = Request.Cookies["DTF_selectedIndex"];
}
}