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

    }

  • 相关阅读:
    args 、kwargs不定参数通过列表、元组、字典传递
    内置函数_eval
    python模块之beautifulSoup
    修改jupyter notebook的默认浏览器
    jupyter notebook自动补全功能实现
    在资源管理器中添加一个共享的网络位置
    在word2010中添加带滚动条的文本框
    Outlook 2010中263邮箱客户端设置
    跳跃游戏
    螺旋矩阵
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172568.html
Copyright © 2011-2022 走看看