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);
            }

    }

  • 相关阅读:
    查看系统的所有port的状态
    python技巧26[python的egg包的安装和制作]
    python类库31[进程subprocess与管道pipe]
    [BuildRelease Management]hudson插件
    python类库31[使用xml.etree.ElementTree读写xml]
    开机自动运行VMWare
    python实例26[计算MD5]
    2021年最新大厂php+go面试题集(四)
    Jumpserver开源跳板机系统
    报错:ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or director(亲测可用)
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172568.html
Copyright © 2011-2022 走看看