CS 页面
public partial class Themaes :PageBase
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void ThemeChanged(object sender, EventArgs e)
{
if (this.UserEntity != null)
{
this.UserEntity.theme = byte.Parse(this.DropDownList1.SelectedValue);
}
else
{
Session["Theme"] = byte.Parse(this.DropDownList1.SelectedValue);
}
Response.Redirect(Request.RawUrl);
}
}源页面
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ThemeChanged">
<asp:ListItem Value="1">请选择</asp:ListItem>
<asp:ListItem Value="2">绿</asp:ListItem>
<asp:ListItem Value="3">红</asp:ListItem>
</asp:DropDownList><br />每次我选择完颜色.这个DropDownList的选项又跳回"请选择"这个选项去了.
不明白。大家给解释下
public partial class Themaes :PageBase
{
protected void Page_Load(object sender, EventArgs e)
{ }
public void ThemeChanged(object sender, EventArgs e)
{
if (this.UserEntity != null)
{
this.UserEntity.theme = byte.Parse(this.DropDownList1.SelectedValue);
}
else
{
Session["Theme"] = byte.Parse(this.DropDownList1.SelectedValue);
}
Response.Redirect(Request.RawUrl);
}
}源页面
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ThemeChanged">
<asp:ListItem Value="1">请选择</asp:ListItem>
<asp:ListItem Value="2">绿</asp:ListItem>
<asp:ListItem Value="3">红</asp:ListItem>
</asp:DropDownList><br />每次我选择完颜色.这个DropDownList的选项又跳回"请选择"这个选项去了.
不明白。大家给解释下
Response.Redirect(Request.RawUrl);
protected override void OnPreInit(EventArgs e)
{
if (Session["Theme"] == null)
Session["Theme"] = byte.Parse(ConfigurationManager.AppSettings["DefaultTheme"].ToString());
if (Session["Language"] == null)
Session["Language"] = ConfigurationManager.AppSettings["DefaultLanguage"].ToString();
this.theme = (byte)Session["Theme"];
this.language = (string)Session["Language"]; if (Session["UserEntity"] != null)
{
this.UserEntity = (UserEntity)Session["UserEntity"];
Session["Language"] = this.UserEntity.language;
Session["Theme"] = this.UserEntity.theme;
this.theme = this.UserEntity.theme;
this.language = this.UserEntity.language;
}
//页面中调用的CSS样式来源此。
Context.Response.Write("<link href='App_Themes/Theme" + this.theme.ToString() + "/css/main.css' rel='stylesheet' type='text/css'>");
base.OnPreInit(e);
}
Response.Redirect("aa.aspx?theme="+this.this.DropDownList1.SelectedValue);
然后在
page_load中指定初始值.
不会吧???if(!this.IsPostBack)
{
if(Request.QueryString("theme")!=null)
{
ddl.selectedValue = .... //最后先判断一下合法性.
}
}
{
if (!this.IsPostBack)
{
if (Request.QueryString["Theme"] == null)
{
DropDownList1.SelectedValue = "1";
}
} }
public void ThemeChanged(object sender, EventArgs e)
{
if (this.UserEntity != null)
{
this.UserEntity.theme = byte.Parse(this.DropDownList1.SelectedValue);
}
else
{
Session["Theme"] = byte.Parse(this.DropDownList1.SelectedValue);
}
//Response.Redirect(Request.RawUrl);
Response.Redirect("Themaes.aspx?Theme=" + this.DropDownList1.SelectedValue);
}
DropDownList1.SelectedValue = Request.QueryString["Theme"];
我想问下。这样的话。我根据每个人保存自己的颜色,取保存的SESSION[THEME]得出不是都是固定的吗/