首页 新闻 搜索 专区 学院

VS2005在代码中指定母版页错误

0
[已解决问题] 解决于 2008-04-09 20:22
VS2005在代码中指定母版页<br><b>分析器错误信息: </b>内容控件必须是内容页中的顶级控件,或是引用母版页的嵌套母版页。<br>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="test._default" %&gt;<br>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;<br><br>&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;<br>&lt;head runat="server"&gt;<br>&nbsp;&nbsp;&nbsp; &lt;title&gt;无标题页&lt;/title&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&nbsp;&nbsp;&nbsp; &lt;form id="form1" runat="server"&gt;<br>&nbsp;&nbsp; &lt;div&gt;<br>&nbsp; <br><br>&lt;asp:Content ID="Content1" ContentPlaceHolderID="cphBody" Runat="Server"&gt;<br>AA&lt;/asp:Content&gt;&nbsp;&nbsp; &lt;/div&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &lt;/form&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;<br><br>using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Collections;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;<br>using System.Threading;<br>using System.Text.RegularExpressions;<br>using System.Globalization;<br>namespace test<br>{<br>&nbsp;&nbsp;&nbsp; public partial class _default : System.Web.UI.Page<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void Page_PreInit(object sender, EventArgs e)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string _Theme = "tfr";<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MasterPageFile = RelativeWebRoot + "themes/" + _Theme + "/site.master";<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public string RelativeWebRoot<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get { return VirtualPathUtility.ToAbsolute(ConfigurationManager.AppSettings["BlogEngine.VirtualPath"]); }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br>}<br><br>
问题补充: 备注:是通过编程方式来指定母版,不是在建立aspx时,直接选择. 我是想通过母版,来实现不同的皮肤
编程入门的主页 编程入门 | 初学一级 | 园豆:185
提问于:2008-03-26 16:41
< >
分享
最佳答案
0
void Page_PreInit(Object sender, EventArgs e) { this.MasterPageFile = "~/NewMaster.master"; } 参考:以编程方式使用 ASP.NET 母版页 http://msdn2.microsoft.com/zh-cn/library/c8y19k6h(VS.80).aspx
风海迷沙 | 老鸟四级 |园豆:4453 | 2008-03-27 11:19
其他回答(1)
0
http://www.cnblogs.com/liubiqu/archive/2008/03/14/1106531.html
丁学 | 园豆:18530 (专家六级) | 2008-03-26 22:57
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册