框架页面尽可以这么用(后置代码中控制框架)

时间:2022-04-23
本文章向大家介绍框架页面尽可以这么用(后置代码中控制框架),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

下面是框架页:

<%@ Page CodeBehind="Frameset.aspx.cs" Language="c#" AutoEventWireup="false" Inherits="IbatisTest.Web.Frameset" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<HTML>
    <HEAD>
        <TITLE>内容框架集</TITLE>
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312">
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
    </HEAD>
    <frameset cols="150,*" id="detail" runat="server">
        <frame name="contents" id="contents" runat=server src=""></frame>
        <frame name="main" id="main" src="" runat="server"></frame>
        <noframes>
            <p id="p1">
                此 HTML 框架集显示多个 Web 页。若要查看此框架集,请使用支持 HTML 4.0 及更高版本的 Web 浏览器。
            </p>
        </noframes>
    </frameset>
</HTML>

后置代码如下:

using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace IbatisTest.Web
{
    /// <summary>
    /// Frameset 的摘要说明。
    /// </summary>
    public class Frameset : System.Web.UI.Page
    {
        protected System.Web.UI.HtmlControls.HtmlGenericControl detail;
        protected System.Web.UI.HtmlControls.HtmlGenericControl contents;
        protected System.Web.UI.HtmlControls.HtmlGenericControl main;
    
        private void Page_Load(object sender, System.EventArgs e)
        {
            detail.Attributes.Add("src","default.aspx");
            detail.Attributes.Add("framespacing", "0") ;
            detail.Attributes.Add("frameborder", "0") ;
            detail.Attributes.Add("marginwidth", "0") ;
            detail.Attributes.Add("marginheight", "0") ;
            detail.Attributes.Add("topmargin", "0") ;
            detail.Attributes.Add("leftmargin", "0") ;

            contents.Attributes.Add("NAME", "hauttop") ;
            contents.Attributes.Add("MARGINHEIGHT", "0") ;
            contents.Attributes.Add("MARGINWIDTH", "0") ;
            contents.Attributes.Add("topmargin", "0") ;
            contents.Attributes.Add("leftmargin", "0") ;
            contents.Attributes.Add("SCROLLING", "no") ;
            contents.Attributes.Add("framespacing", "0") ;
            contents.Attributes.Add("frameborder", "0") ;

            contents.Attributes.Add("src","default.aspx");
            main.Attributes.Add("NAME", "corpscentre") ;
            main.Attributes.Add("MARGINHEIGHT", "0") ;
            main.Attributes.Add("MARGINWIDTH", "0") ;
            main.Attributes.Add("frameborder", "1") ;
            main.Attributes.Add("SCROLLING", "auto") ;
            main.Attributes.Add("framespacing", "0") ;
            main.Attributes.Add("topmargin", "1") ;
            main.Attributes.Add("leftmargin", "0") ;

            main.Attributes.Add("src","Person.aspx");
        }

        #region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {    
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion
    }
}