vs2005中母版页嵌套无法切换到设计视图。。。( 设计视图不支持创建或编辑嵌套的母版页)

最近在学.net,下载了东西,都是用了母版页,切换不到设计视图。。问了老师终于找到办法了,之前有在网上找到说在MasterPageFile后添加个空格就行了,但是我的不行,还是错了。。

假设有母版页第一级母版页MasterPage.master,第二级母版页MasterPage2.master是MasterPage.master的内容页,Default.aspx是MasterPage2.master的内容页。

首先新增一个类:BasePage.cs

C#代码:

  1. using System;   
  2. using System.Data;   
  3. using System.Configuration;   
  4. using System.Web;   
  5. using System.Web.Security;   
  6. using System.Web.UI;   
  7. using System.Web.UI.WebControls;   
  8. using System.Web.UI.WebControls.WebParts;   
  9. using System.Web.UI.HtmlControls;   
  10.   
  11. public class BasePage : System.Web.UI.Page   
  12. {   
  13.     private string runtimeMasterPageFile;   
  14.     public string RuntimeMasterPageFile   
  15.     {   
  16.         get  
  17.         {   
  18.             return runtimeMasterPageFile;   
  19.         }   
  20.         set  
  21.         {   
  22.             runtimeMasterPageFile = value;   
  23.         }   
  24.     }   
  25.   
  26.     protected override void OnPreInit(EventArgs e)   
  27.     {   
  28.         if (runtimeMasterPageFile != null)   
  29.         {   
  30.             this.MasterPageFile = runtimeMasterPageFile;   
  31.         }   
  32.         base.OnPreInit(e);   
  33.     }   
  34. }  

然后修改Default.aspx的最上面这一行代码:

修改前:

 

    • <%@ Page Language="C#" MasterPageFile="MasterPage2.master" AutoEventWireup="true" 
    •  CodeFile="Default.aspx.cs" Inherits="_Default" %>  

 

修改后:

  1. <%@ Page Language="C#" MasterPageFile="" RuntimeMasterPageFile="MasterPage2.master" 
  2. CodeFileBaseClass="BasePage" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" >  

最后修改Default.aspx的后台代码:

修改前:

             public partial class Demo_Default : System.Web.UI.Page 

修改后:

            

 

 

            public partial class _Default : BasePage  

这样就可以打开设计视图了。。。

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值