主要做了一个基页:BasePage 在此基页上布局, default页继承它,并根据url参数,自动加载不同的处理用户控件。
1、BasePage 页:
------------------------------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
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 PhsResManagerWebpro
{
/// <summary>
/// BasePage 的摘要说明。
/// </summary>
public class BasePage : System.Web.UI.Page
{
//用户控件
protected PhsResManagerWebpro.UserControls.headermenu headermenu1;
protected PhsResManagerWebpro.UserControls.caption caption1;
protected PhsResManagerWebpro.UserControls.menu menu1;
protected PhsResManagerWebpro.UserControls.cauda cauda1;
private void Page_Load(object sender, System.EventArgs e)
{
LogionPage(); //也面加载
}
#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
#region 页面加载
private void LogionPage()
{
SetCssFile("defaultCss.css"); //设置Css样式
SetLayout(); //页面布局
}
#endregion
#region 页面布局
/// <summary>
/// 页面布局
/// </summary>
private void SetLayout()
{
Control Form=this.Page.Controls[1]; //页表单form对象
//标题Panel创建
System.Web.UI.WebControls.Panel PnlCaption=new Panel();
PnlCaption.ID="PanCaption";
PnlCaption.Width=970;
PnlCaption.Height=80;
PnlCaption.CssClass="panel15";
//主菜单Panel创建
System.Web.UI.WebControls.Panel PnlMainmenu=new Panel();
PnlMainmenu.ID="PnlMainmenu";
PnlMainmenu.Width=970;
PnlMainmenu.Height=10;
PnlMainmenu.CssClass="panel10";
//内容框架Panel创建
System.Web.UI.WebControls.Panel PnlMain=new Panel();
PnlMain.ID="PnlMain";
PnlMain.Width=970;
PnlMain.Height=1000;
PnlMain.CssClass="panel0";
//页尾Panel创建
System.Web.UI.WebControls.Panel pnlEnd=new Panel();
pnlEnd.ID="pnlEnd";
pnlEnd.Width=970;
pnlEnd.Height=90;
pnlEnd.CssClass="panel15";
//加载布局
Form.Controls.Add(PnlCaption);
Form.Controls.Add(PnlMainmenu);
Form.Controls.Add(PnlMain);
Form.Controls.Add(pnlEnd);
//导航Panel创建
System.Web.UI.WebControls.Panel pnlMenu=new Panel();
pnlMenu.ID="pnlMenu";
pnlMenu.Width=250;
pnlMenu.Height=1000;
pnlMenu.CssClass="panel15left";
//内容Panel创建
System.Web.UI.WebControls.Panel pnlContent=new Panel();
pnlContent.ID="pnlContent";
pnlContent.Width=718;
pnlContent.Height=1000;
pnlContent.CssClass="panel15right";
//加载内容框架布局
PnlMain.Controls.Add(pnlMenu);
PnlMain.Controls.Add(pnlContent);
//菜单用户控件
headermenu1=(PhsResManagerWebpro.UserControls.headermenu)this.LoadControl("UserControls/headermenu.ascx");
//标题头用户控件
caption1=(PhsResManagerWebpro.UserControls.caption)this.LoadControl("UserControls/caption.ascx");
//导航菜单用户控件
menu1=(PhsResManagerWebpro.UserControls.menu)this.LoadControl("UserControls/menu.ascx");
//页尾 用户控件
cauda1=(PhsResManagerWebpro.UserControls.cauda)this.LoadControl("UserControls/cauda.ascx");
//加载自定义控件
PnlCaption.Controls.Add(caption1);
PnlMainmenu.Controls.Add(headermenu1);
pnlMenu.Controls.Add(menu1);
pnlEnd.Controls.Add(cauda1);
//页面的处理控件加载
SetContentUsercontrls(pnlContent);
}
#endregion
#region Css样式加载
/// <summary>
/// Css样式加载
/// </summary>
private void SetCssFile(string strCssFileName)
{
string strCssUrl=@"<link href=Css/"+strCssFileName+" rel=stylesheet type=text/css>"; //Css路径
Response.Write(strCssUrl); //Css路径引入
}
#endregion
#region 页面处理控件加载
/// <summary>
/// 页面的处理控件加载
/// </summary>
/// <param name="pnlMain"></param>
public void SetContentUsercontrls(System.Web.UI.WebControls.Panel pnlMain)
{
if(Request.Params["PageName"]==null)
return;
string PageName=Request.Params["PageName"].ToString(); //得到请求的处理页面名称
if(PageName==null || PageName=="")
return;
else
{
//根据连接串Key值,从XML里读取Value值
DataSet ds=new DataSet();
ds.ReadXml(MapPath("urlConfig.xml"));
for(int i=0;i<ds.Tables[0].Rows.Count;i++)
{
if(ds.Tables[0].Rows[i]["key"].ToString()==PageName)
{
PageName=ds.Tables[0].Rows[i]["value"].ToString();
break;
}
}
}
//加载用户控件
Control cTemp=(Control)this.LoadControl(PageName);
pnlMain.Controls.Add(cTemp);
}
#endregion
}
}
urlConfig.xml文件:
-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<urlConfig>
<urlItem>
<key>WGinfoUserControl</key>
<value>BLLUserContrls/WGinfoUserControl.ascx</value>
</urlItem>
<urlItem>
<key></key>
<value></value>
</urlItem>
<urlItem>
<key></key>
<value></value>
</urlItem>
</urlConfig>
defaultCss.css文件:
-----------------------------------------------------
body
{
FONT-SIZE: 14px;
COLOR: darkslategray;
background-color:White;
text-align:center;
}
.panel15
{
BORDER-RIGHT: buttonshadow 1px solid;
BORDER-TOP: buttonshadow 1px solid;
BORDER-LEFT: buttonshadow 1px solid;
BORDER-BOTTOM: buttonshadow 1px solid;
background-color: #f5f5f5;
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
PADDING-TOP: 0px;
MARGIN: 2px 0px 1px;
text-align:left;
}
.panel0
{
BORDER-RIGHT: buttonshadow 0px solid;
BORDER-TOP: buttonshadow 0px solid;
BORDER-LEFT: buttonshadow 0px solid;
BORDER-BOTTOM: buttonshadow 0px solid;
background-color: #f5f5f5;
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
PADDING-TOP: 0px;
MARGIN: 2px 0px 1px;
text-align:left;
}
.panel10
{
BORDER-RIGHT: buttonshadow 1px solid;
BORDER-TOP: buttonshadow 0px solid;
BORDER-LEFT: buttonshadow 1px solid;
BORDER-BOTTOM: buttonshadow 0px solid;
background-color: #f5f5f5;
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
PADDING-TOP: 0px;
MARGIN: 2px 0px 1px;
text-align:left;
}
.panel5
{
BORDER-RIGHT: buttonshadow 0px solid;
BORDER-TOP: buttonshadow 1px solid;
BORDER-LEFT: buttonshadow 0px solid;
BORDER-BOTTOM: buttonshadow 1px solid;
background-color: #f5f5f5;
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
PADDING-TOP: 0px;
MARGIN: 2px 0px 1px;
text-align:left;
}
.panel15right
{
BORDER-RIGHT: buttonshadow 1px solid;
BORDER-TOP: buttonshadow 1px solid;
BORDER-LEFT: buttonshadow 1px solid;
BORDER-BOTTOM: buttonshadow 1px solid;
background-color: #f5f5f5;
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
PADDING-TOP: 0px;
MARGIN: 2px 0px 1px;
text-align:left;
}
.panel15left
{
BORDER-RIGHT: buttonshadow 1px solid;
BORDER-TOP: buttonshadow 1px solid;
BORDER-LEFT: buttonshadow 1px solid;
BORDER-BOTTOM: buttonshadow 1px solid;
background-color: #f5f5f5;
float:left;
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
PADDING-TOP: 0px;
MARGIN: 2px 0px 1px;
text-align:left;
}
.panel15right
{
BORDER-RIGHT: buttonshadow 1px solid;
BORDER-TOP: buttonshadow 1px solid;
BORDER-LEFT: buttonshadow 1px solid;
BORDER-BOTTOM: buttonshadow 1px solid;
background-color: #f5f5f5;
float:right;
PADDING-RIGHT: 0px;
PADDING-LEFT: 0px;
PADDING-BOTTOM: 0px;
PADDING-TOP: 0px;
MARGIN: 2px 0px 1px;
text-align:left;
}
.ButtonCss {
font-family: "Tahoma", "宋体";
font-size: 9pt; color: #003399;
border: 1px #003399 solid;
color:006699;
BORDER-BOTTOM: #93bee2 1px solid;
BORDER-LEFT: #93bee2 1px solid;
BORDER-RIGHT: #93bee2 1px solid;
BORDER-TOP: #93bee2 1px solid;
background-image:url(../Images/bluebuttonbg.gif);
background-color: #e8f4ff;
CURSOR: hand;
font-style: normal ;
}
.TextBoxCss
{
font-family: "Tahoma", "宋体";
font-size: 9pt;
color: #003399;
}
.InputCss {
font-size: 9pt;
color: #003399;
font-family: "宋体";
font-style: normal;
border-color: #93BEE2 #93BEE2 #93BEE2 #93BEE2 ;
border: 1px #93BEE2 solid;
}
DefaultIndex.aspx.cs
-------------------------------------------
using System;
using System.Collections;
using System.ComponentModel;
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 PhsResManagerWebpro
{
/// <summary>
/// DefaultIndex 的摘要说明。
/// </summary>
public class DefaultIndex :BasePage
{
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
#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
}
}