问题描述
- .net如何用cookies动态切换主题
-
我做了两个主题,一个绿色背景,一个红色背景,但一在网页上加载只显示绿色,多次切换主题后还是绿色,求指点,为什么就切换不到红色
public partial class _Default : System.Web.UI.Page
{
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request.Cookies["Theme"] != null)
this.Theme = Request.Cookies["Theme"].Value;
}
protected void Page_Load(object sender, EventArgs e)
{
//if (IsPostBack==false)
//{
// DropDownList dll = (DropDownList)Master.FindControl("DropDownList1");
// dll.SelectedValue = this.Theme;
//}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Response.Cookies["Theme"].Value = DropDownList1.SelectedValue;
Response.Cookies["Theme"].Expires=DateTime .Now.AddDays(7);
//Response.Redirect(Request.Url.ToString());
}
}
我做了两个主题,一个绿色背景,一个红色背景,但一在网页上加载只显示绿色,多次切换主题后还是绿色,求指点,为什么就切换不到红色
解决方案
this.Theme = Request.Cookies["Theme"].Value;
下个断点看下
时间: 2024-10-28 12:56:48