1.构造一个函数,继承System.Web.UI.Page
   /// <summary>
    /// Brand的构造函数
    /// </summary>
    public class CBrandBaseBage : System.Web.UI.Page
    {
       protected string BrandId;

       public CBrandBaseBage()
       {
            //ShowPage(); showpage给子类用,如果子类用session[""]=""会提示page里缺少httpmodule的statues
            //this.Init += new EventHandler(Page_Init); 
            this.Load += new EventHandler(BasePage_Load);
        }
       private void BasePage_Load(object sender, EventArgs e)
       {
           ShowPage();//showpage要放在load里面才能正常使用session
           //判断是否存在该品牌BrandId
           
       }
       //抛出一个方法给子类重写
       protected virtual void ShowPage()
       {
           //虚方法代码
       }

2.子页面继承

 //父类虚方法,在Init之前执行
        protected override void ShowPage()
        {
            //base.ShowPage();
            Id = Function.SqlFilter(DtRequest.GetQueryInt("ID", 0).ToString());
            if (Id == "0") return;
            if (string.IsNullOrEmpty(Id)) return;
            if (System.Web.HttpContext.Current == null) return;
            HttpContext.Current.Session["bid"] = Id;
            HttpContext.Current.Session.Timeout = 45;
            Function.WriteCookie("bid", "ZT", Id);
        }

  

posted on 2015-06-17 18:30  等风起  阅读(475)  评论(0编辑  收藏  举报