原文地址:http://www.codeproject.com/KB/applications/MasterPagesASP.aspx
[原文×××]


在asp.net 2.0中使用母版页和工厂方法模式


原文发布日期:2007.01.18
作者:ssaud
翻译:webabcd


介绍
这里我讲解如何充分发挥母版页的优势。关于母版页的优点有大量的文章进行说明,参看http://www.odetocode.com/Articles/450.aspx 此文当然和那些文章不相同。有时,你会经常碰到这样的场景:相同的用户界面(GUI),但是不同的业务逻辑,如图所示。因此,你会考虑使用用户控件来保持各个页面的标准外观。但如果你听我说明一下如何使用工厂模式设计的母版页,你就会感觉酷毙了!这里我使用了带单击功能的表格(Grid)。
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_工厂
 
背景
阅读此文之前你必须对母版页的相关知识有所了解,这样你能更好的理解此文


工作流程
当用户从菜单中选择订单详情时,父表格将会填充所有订单列表,子表格将会填充包含在此订单的产品列表。当用户选择职员时,父表格将会填充所有职员列表,子表格将会填充选中职员的地区列表。有2个内容页来显示选中项的相关信息。


关于代码
下载的代码包括dbcontroller1 helper类。你只需修改数据库链接字符串来链接到你的SQL server就可以了。后台数据库是SQL server自带的Northwind数据库。


概述
此应用程序包括一个母版页,其中有1个菜单控件和2个表格控件(父表格和子表格),其中子表格的数据源依赖父表格。

我们首先看看Northwind数据库中订单和订单明细表的例子。我们在父表格中填充订单列表,当选中其中一个订单时,子表格填充该订单包括的产品列表。这个场景同样适用于职员和职员地区的案例。同样,在应用程序中经常有类似的场景。你准备怎么做?创建大量独立的类似的页面?还是创建一个用户控件?尽管用户控件是个不错的选择,但这里我们用母版页来实现这个需求。

在进一步讲解之前,我们先来了解一下工厂模式到底是什么?


工厂方法
工厂方法(FactoryMethod)模式是类的创建模式,其用意是定义一个创建产品对象的工厂接口,将实际创建工作推迟到子类中(GOF)。在工厂方法模式中,核心的工厂类不再负责所有产品的创建,而是将具体创建工作交给子类去做。这个核心类仅仅负责给出具体工厂必须实现的接口,而不接触哪一个产品类被实例化这种细节。这使得工厂方法模式可以允许系统在不修改工厂角色的情况下引进新产品。

这就是我们所期望的。下图解释了参数化工厂方法。工厂方法消除了代码中和特定应用程序相关的类,代码仅仅定义了基类接口,因此它可以和与基类具有同样的接口的用户定义的类配合工作。
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_工厂_02
 
实现工厂方法
我们创建一个抽象类Base,其中包括了4个抽象方法。Order 和 Employee类继承抽象类Base。下面是Base类的代码。BindParentGrid将把Parent数据源绑定到父表格中,Parent数据源既可以是Order列表,也可以是Employee列表,这看用户的选择了。BindChildGrid方法Child数据源(产品或者地区)绑定到子表格中。getParentData返回Parent数据源信息,getChildData返回子数据源信息。Key是父表格传递给方法的参数。
///<summary>
/// 抽象类
///</summary>
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03public abstract class Base
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03{    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        public abstract void BindParentGrid(DataDigest.WebControls.GridView gvParent);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        public abstract void BindChildGrid(DataDigest.WebControls.GridView gvChild, string ParentId);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        public abstract DataSet getParentData();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        public abstract DataSet getChildData(string Key);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03}
 
我们从抽象类继承过来两个类BIOrderMaster 和 BIEmployeeMaster,来控制表格绑定。下面是其中一个继承类的代码。我们不再讨论数据访问组件,详细情况请直接看附件代码。
///<summary>
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03            /// 具体类
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03            ///</summary>
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03            public class BIOrderMaster : Base
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03            {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                 private DAccessOrder Orders = newDAccessOrder();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                 private DataSet dsParent = newDataSet();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                 public BIOrderMaster()    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                 {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        dsParent = Orders.getOrders();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                 }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                 public override void BindParentGrid(DataDigest.WebControls.GridView gvParent)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                 {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        if (dsParent == null) {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                             dsParent = Orders.getOrders();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        string[] key = newstring[1];
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        key[0] = "OrderID";
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        gvParent.DataSource = null;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        gvParent.Columns.Clear();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        gvParent.DataSource = dsParent;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        gvParent.DataKeyNames = key;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        BoundField TtlCoNm = newBoundField();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        TtlCoNm.DataField = "OrderID";
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        TtlCoNm.HeaderText = "Order ID";
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        gvParent.Columns.Add(TtlCoNm);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        TtlCoNm.ItemStyle.Width = 600;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        gvParent.DataBind();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                public override void BindChildGrid(DataDigest.WebControls.GridView gvChild, string ParentId)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     string[] key = newstring[1];
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     key[0] = "ProductID";
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     DataSet dsChild = Orders.getProducts(ParentId);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     gvChild.SelectedIndex = -1;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     gvChild.DataSource = null;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     gvChild.Columns.Clear();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     gvChild.DataSource = dsChild;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     gvChild.DataKeyNames = key;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     BoundField BrName = newBoundField();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     BrName.DataField = "ProductName";
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     BrName.HeaderText = "Product Name";
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     gvChild.Columns.Add(BrName);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     BrName.ItemStyle.Width = 600;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     gvChild.DataBind();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                public override DataSet getParentData()
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     return dsParent;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                public override DataSet getChildData(string Key)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                     return Orders.getProducts(Key);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03     }
 
无论何时用户从菜单中选择一个特定的项时,我们把页标识(page identity)存到Session中。母版页把页标识传给工厂类,工厂类返回匹配的基类类型的对象。我们的具体类 BIOrderMaster 和 BIEmployeeMaster 具有相同的类型,因为他们共享基类的接口。我们的工厂类如下所示:


工厂类
///<summary>
/// 返回实现抽象基类的对象
///</summary>
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03public class Factory
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03{                    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        public Factory()
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        public Base GetObject(string type)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                Base objbase = null;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                switch (type)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        case "Order Detail":
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                objbase = newBIOrderMaster();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                break;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        case "Employee Territorie":
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                objbase = newBIEmployeeMaster();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                break;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        default:
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                throw new Exception("Unknown Object");
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                return objbase;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03}
 
母版页
我们看看当用户请求两个内容页之一——订单详情页时,将会发生什么。当我们用母版页工作时,事件的执行顺序很重要。内容页的Page load事件在母版页Page load事件之前发生,而母版页的page init事件在内容页的page init之前触发。这个顺序非常重要,我们将在后面讨论。目前,我们仅仅需要知道这些事件执行的顺序
  ·Master – initialize. 
  ·Content- initialize. 
  ·Content- load. 
  ·Master – load. 
  ·Content- render. 
  ·Master- render. 

我们挨个事件观察母版页后面的代码

首先,我们实例化一个工厂类对象,同时申明一个类型是Base的对象。我们注意到母版页代码中有好几个事件。这些事件用于通知内容页,当母版页中的选择改变时,内容页也必须做相应变化。我不想就自定义事件和委托做过多讲解,因为有很多这方面的资料可得。我们还定义了几个公共属性。
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03private Factory Factory = newFactory();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03private Base currentObject;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03public event GridSelectionChanged GridChanged;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03public event SecondryGridSelectionChanged ChildGridChanged;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03public string mainTitle
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03{
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    set
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        pageTitle.Text = value;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03}
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03public Base myObject
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03{
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        get
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                return currentObject;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03}
 
在page init事件中,我们要求工厂得到合适的Base类型对象,属性myObject返回这个新创建的对象。这个属性在内容页使用,用于在Page Load事件中得到当前具体对象。还记得我们说过的事件的执行顺序吧。在page_init事件中,我们调用factory类getObject方法。如果我们把代码替换到page load事件中,我们就不能内容页得到它的引用,因为,内容页的page load事件在母版页的page load事件之前发生。
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03protected void Page_Init(object sender, System.EventArgs e)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03{
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        if (Session["PageName"] != null)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                if (Session["PageName"].ToString() !=    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        "Home")
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        currentObject = Factory.GetObject(Session[
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                "PageName"].ToString());
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03}
 
在母版页的page load事件中,我们请求Base类型对象currentObject绑定父表格。相似的,在父表格SelectedIndexChanged事件中,我们请求currentObject绑定子表格。在GV_TitleCompany_SelectedIndexChanged事件中,我们通知当前页,一个grid selection动作发生了。我们扩展了eventArg类,以处理事件消息——即表格的Datakey
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03protected void Page_Load(object sender, EventArgs e)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03{
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        if (!Page.IsPostBack)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                if (Session["PageName"] != null)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        if (Session["PageName"].ToString()    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                != "Home")
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                currentObject.BindParentGrid(
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                                            GV_TitleCompany);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        else
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                myPanel.Visible = false;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                Panel1.Visible = false;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                ClearGrid();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                else
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        myPanel.Visible = false;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        Panel1.Visible = false;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                        ClearGrid();
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03}
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03protected void GV_TitleCompany_SelectedIndexChanged(
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                                                    object sender, EventArgs e)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03{
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        GridViewRow row = GV_TitleCompany.SelectedRow;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        currentObject.BindChildGrid(GV_BranchName,    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03             GV_TitleCompany.DataKeys[GV_TitleCompany
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03             .SelectedIndex][0].ToString().Trim());
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        MasterGridEventArgument eventArgs = new    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03             MasterGridEventArgument(GV_TitleCompany.DataKeys[
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03             GV_TitleCompany.SelectedIndex].Value.ToString()
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03             .Trim());
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        if (GridChanged != null)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                GridChanged(this, eventArgs);
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03}
 
现在,我们来看看其中的一个内容页


订单页面
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03public partial class Pages_Default : System.Web.UI.Page
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03{
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        privateBase Orders;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        protectedvoid Page_Load(object sender, EventArgs e)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                Pages_MasterGrid myMaster = (Pages_MasterGrid)this.Master;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                myMaster.mainTitle = "Order Information";
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                Orders = myMaster.myObject;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        protected void Page_Init(object sender, System.EventArgs e)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                Pages_MasterGrid myMaster = (Pages_MasterGrid)this.Master;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                myMaster.GridChanged += FillControls;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                myMaster.ChildGridChanged += FillChildInfo;
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        protected void FillControls(object sender, MasterGridEventArgument e)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                 // Code
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03    
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        protected void FillChildInfo (object sender, DetailGridEventArgument e)
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        {
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03                // Code
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03        }
[翻译]在asp.net 2.0中使用母版页和工厂方法模式_模式_03}
 
 
在page_init事件中,我们增加自定义事件的处理逻辑,这些自定义事件将由母版页的父表格和子表格调用,然后在page load事件中,我们通过公共属性给Page Title赋值,我们也设置母版页的currentObject。我们给GridChanged事件添加了FillControl函数,以及给ChildGridChanged事件添加了FillChildInfo函数,这些函数将填充Multiview控件中所包括的控件。全部代码请参见源码


结语
这就是所有的内容,我们已经完成了母版页和工厂模式。欢迎大家对此文做出修改和评论。谢谢!