在系统的,我的所有页面都继承于BasePage..在BasePage页里面的<head></head>里,我插入了一个样式表..但是从BasePage页继承下去的网页..竟然应用不了那个样式表..难道说,我每一页都要在<head></head>中插入了样式表引用吗?那"继承"这个字眼不就废了?怎么办呀?

解决方案 »

  1.   

    写个BasePage类。继承page
    public class BasePage :System.Web.UI.Page
    /// <summary>
    /// 页面加载时发生
    /// </summary>
    protected virtual void BasePage_Load(object sender,System.EventArgs e)
    {
    if(Response.ContentType.ToLower() == "text/html")
    this.InsertHeader();
    }
    /// <summary>
    /// 将指定的字符内容插入页面的<head>区
    /// </summary>
    private void InsertHeader()
    {
    //获取baseWeb项脚本路径
    string commonScript = "<script......></script>";//head中的脚本引用
    string cssStyle = “<link...... >”//样式引用

    System.Web.UI.LiteralControl literal = 
    this.Page.Controls[0] as System.Web.UI.LiteralControl;
    if(literal != null)
    {
    Regex reg = new Regex(@"</title>",RegexOptions.IgnoreCase);
    string strHeader = literal.Text;
    string strFormat = "</title>\n{0}\n{1}\n";
    strFormat = string.Format(strFormat,commonScript,cssStyle);
    literal.Text = reg.Replace(strHeader,strFormat);
    }
    }
      

  2.   

    pagebase类中别忘了加上
    protected override void OnInit(EventArgs e)
    {
    this.Load += new System.EventHandler(this.BasePage_Load);
    base.OnInit(e);

    }
      

  3.   

    @"</title>",這個@起什麽作用呢,不要的話有差別嗎
      

  4.   

    TO:回复人: jijl2001(jijl2001) 看来你对继承也不是很懂呀,呵呵..我都说了, humin1906(HJM) 的方法是可行的..再过一天我就要结贴了.