System.Web.UI.MasterPage 一点理解

<!--  版模页  -->
<% @ Master Language = " C# "  AutoEventWireup = " true "  Inherits = " DuwControls.DuwDefaultMasterPage "   %>
<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >
< html xmlns = " http://www.w3.org/1999/xhtml " >
< head runat = " server " >     
    
< asp:contentplaceholder id = " CHead "  runat = " server " >
    
</ asp:contentplaceholder >
</ head >
< body >
    
< form id = " form1 "  runat = " server " >
        
< asp:ContentPlaceHolder ID = " ScriptMan "  runat = " server " >
               ScriptMain
        
</ asp:ContentPlaceHolder >
        
< asp:ContentPlaceHolder ID = " CTop "  runat = " server " >
               CTop
        
</ asp:ContentPlaceHolder >
        
< asp:ContentPlaceHolder ID = " CLeft "  runat = " server " >
               CLeft
        
</ asp:ContentPlaceHolder >
        
< asp:ContentPlaceHolder ID = " CMain "  runat = " server " >
               CMain
        
</ asp:ContentPlaceHolder >
        
< asp:ContentPlaceHolder ID = " CRight "  runat = " server " >
               CRight
        
</ asp:ContentPlaceHolder >
        
< asp:ContentPlaceHolder ID = " CFoot "  runat = " server " >
               CFoot
        
</ asp:ContentPlaceHolder >
    
</ form >
</ body >
</ html >
ContentPlaceHolder 为模版部分的占用位置


// 模版页后台,继承自系统 System.Web.UI.MasterPage
using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  System.Web;

namespace  DuwControls
{
    
public class DuwDefaultMasterPage : MasterPage
    
{
        
private ContentPlaceHolder _CHead;
        
private ContentPlaceHolder _CTop;
        
private ContentPlaceHolder _CLeft;
        
private ContentPlaceHolder _CMain;
        
private ContentPlaceHolder _CRight;
        
private ContentPlaceHolder _CFoot;
        
private ContentPlaceHolder _ScriptMan;

        
public ContentPlaceHolder CHead get return _CHead; } }
        
public ContentPlaceHolder CTop get return _CTop; } }
        
public ContentPlaceHolder CLeft get return _CLeft; } }
        
public ContentPlaceHolder CMain get return _CMain; } }
        
public ContentPlaceHolder CRight get return _CRight; } }
        
public ContentPlaceHolder CFoot get return _CFoot; } }
        
public ContentPlaceHolder ScriptMan get return _ScriptMan; } }

        
protected override void OnInit(EventArgs e)
        
{
            
foreach (Control ctrl in this.Controls)
            
{
                
if (ctrl is System.Web.UI.HtmlControls.HtmlHead)//模版Head头部部分
                {
                    
foreach (Control ctl in ctrl.Controls)
                    
{
                        
if (ctl is ContentPlaceHolder)
                        
{
                            _CHead 
= ctl as ContentPlaceHolder;
                        }

                    }

                }

                
else if (ctrl is System.Web.UI.HtmlControls.HtmlForm)//模版Form主体部分
                {
                    
foreach (Control ctl in ctrl.Controls)
                    
{
                        
if (ctl is ContentPlaceHolder)
                        
{
                            
switch (ctl.ID)
                            
{
                                
case "CTop":
                                    _CTop 
= ctl as ContentPlaceHolder;
                                    
break;
                                
case "CLeft":
                                    _CLeft 
= ctl as ContentPlaceHolder;
                                    
break;
                                
case "CMain":
                                    _CMain 
= ctl as ContentPlaceHolder;
                                    
break;
                                
case "CRight":
                                    _CRight 
= ctl as ContentPlaceHolder;
                                    
break;
                                
case "CFoot":
                                    _CFoot 
= ctl as ContentPlaceHolder;
                                    
break;
                                
case "ScriptMan":
                                    _ScriptMan 
= ctl as ContentPlaceHolder;
                                    
break;
                                
default:
                                    
break;
                            }

                        }

                    }

                }

            }

            
base.OnInit(e);
        }

    }

}




// 页面.cs运用部分
using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Web.UI;
using  System.Web.UI.WebControls;
using  DuwCompontents;
using  System.Text.RegularExpressions;
using  System.IO;
using  System.Web;

namespace  DuwControls
{
    
public class DuwPage : Page
    
{       
        
属性

        
事件

}




// aspx页面部分
<% @ Page Language = " C# "  MasterPageFile = " ~/Themes/Default/Default.master "   ValidateRequest = " false "
    Inherits
= " DuwControls.DuwPage "  SkinType = " default "   %>
< asp:Content ID = " Content1 "  ContentPlaceHolderID = " CHead "  Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content2 "  ContentPlaceHolderID = " ScriptMan "  Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content3 "  ContentPlaceHolderID = " CTop "  Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content4 "  ContentPlaceHolderID = " CLeft "  Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content5 "  ContentPlaceHolderID = " CMain "  Runat = " Server " >       
</ asp:Content >
< asp:Content ID = " Content6 "  ContentPlaceHolderID = " CRight "  Runat = " Server " >
</ asp:Content >
< asp:Content ID = " Content7 "  ContentPlaceHolderID = " CFoot "  Runat = " Server " >
</ asp:Content >
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值