zoukankan      html  css  js  c++  java
  • 如何定义其他页面的基类

    public class FriendsBase : System.Web.UI.Page  //必须继承于Page类
        {
            
    protected string HeaderMessage = String.Empty;
            
    protected string HeaderIconImageUrl = String.Empty;

            FriendsFooter _footer;
            FriendsHeader _header;
            SubHeader _subheader;
    //重写OnInit方法,将一些自定义控件及用户控件载入,并都放入0位置
            protected override void OnInit(EventArgs e)
            
    {
                _header 
    = (FriendsHeader) LoadControl
                    (Request.ApplicationPath 
    + Path.AltDirectorySeparatorChar +
                    
    "Controls/FriendsHeader.ascx");
                _footer 
    = (FriendsFooter) LoadControl
                    (Request.ApplicationPath 
    + Path.AltDirectorySeparatorChar +
                    
    "Controls/FriendsFooter.ascx");

                _subheader 
    = new SubHeader();

                
    // Add to the Controls hierarchy to get proper
                
    // event handling, on rendering we position them
                Page.Controls.AddAt(0, _header);
                Page.Controls.AddAt(
    0, _subheader);
                Page.Controls.AddAt(
    0, _footer);
                
    base.OnInit(e);
            }

    //重写Render方法
            protected override void Render(System.Web.UI.HtmlTextWriter writer)
            
    {
                
    //移除页面类所包含的各个层次级别中的控件 Remove the controls from their current place in the hierarchy
                Page.Controls.Remove(_header);
                Page.Controls.Remove(_subheader);
                Page.Controls.Remove(_footer);

                Debug.Assert(
                    Page.Controls[
    1].ToString()=="System.Web.UI.HtmlControls.HtmlForm"
                    
    "Form control not found",
                    
    "Any FriendsReunion page requires that a Form control be " + 
                    
    "located at index 1 of the Page.Controls collection");

                
                
    // 页面Page为索引号为1的控件Get a reference to the form control
                HtmlForm form = (HtmlForm)Page.Controls[1];
                
                
    //在页面上重新分配各种控件 Reposition the controls on the page
                form.Controls.AddAt(0, _header );
                form.Controls.AddAt(
    1, _subheader );
                form.Controls.AddAt(form.Controls.Count, _footer );


                
    //Set current values
                _header.Message = HeaderMessage;
                _header.IconImageUrl 
    = HeaderIconImageUrl;
    //调用基类的Render方法
                base.Render(writer);
            }

    }

  • 相关阅读:
    “指定的SAS安装数据(sid)文件不能用于选定的SAS软件订单
    windows下如何快速优雅的使用python的科学计算库?
    量化分析师的Python日记【第1天:谁来给我讲讲Python?】
    Python的lambda函数与排序
    使用python管理Cisco设备-乾颐堂
    python移除系统多余大文件-乾颐堂
    python算法
    python实现高效率的排列组合算法-乾颐堂
    使用python把图片存入数据库-乾颐堂
    Python将阿拉伯数字转化为中文大写-乾颐堂
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172568.html
Copyright © 2011-2022 走看看