页面级的继承public partial class Default : BasePage
其他页面要引用的cs
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public class BasePage : System.Web.UI.Page
{
/// <summary>
///
/// </summary>
/// <param name="e"></param>
protected override void OnPreInit(EventArgs e)
{
// 这句话加不加就是问题的关键,不会将样式应用到前台,(不加将不会实现,加了能够实现)
base.OnPreInit(e);
}
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_PreInit(object sender, EventArgs e)
{
// 是否为空
if (Session["Theme"] == null)
{
// 默认主题
this.Theme ="Default";
}
else
{
// 当前选择的主题
this.Theme = Session["Theme"].ToString();
}
}
}
Default 页面的cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class Default : BasePage //应用了上面的东西
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ddlSkin_SelectedIndexChanged(object sender, EventArgs e)
{
//System.Configuration.ConfigurationManager.AppSettings["Theme"];
if (!String.IsNullOrEmpty (this.ddlSkin.SelectedValue))
{
Session["Theme"] = this.ddlSkin.SelectedValue;
Response.Redirect("Default.aspx");
}
}
}