【问题标题】:Using master page with jQuery使用带有 jQ​​uery 的母版页
【发布时间】:2014-01-15 08:17:50
【问题描述】:

我有一个问题...

我有一个新项目创建母版页(site.master)时,当调用另一个页面(如(home.aspx)时,页面会出错。

这是一个错误:

“/”应用程序中的服务器错误。 内容控件必须是内容页或引用母版页的嵌套母版页中的顶级控件。 说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:System.Web.HttpException:内容控件必须是内容页或引用母版页的嵌套母版页中的顶级控件。 源错误: 在执行当前 Web 请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常起源和位置的信息。

这是我的主页

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Masterpage.master.cs" 

Inherits="WebApplication2.Masterpage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="CSS/jquery.mobile-1.4.0.min.css" />
    <script type="text/javascript" src="JS/Jquery.min1.js"></script>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
    </div>
    </form>
</body>
</html>

这是 home.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="WebApplication2.home" MasterPageFile="~/Masterpage.Master"  %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
   <body>
   <div data-role="page">
   <div data-role="header" data-theme="b">
           </div>
   <div data-role="content">
                <ul data-role="listview" data-inset="true">
                <li><a href="#" data-role="button" id="btn_group1" data-icon="heart">1</a></li>
                <li><a href="#" data-role="button" id="btn_group2" data-icon="star">2</a></li>
                <li><a href="#" data-role="button" id="btn_group3" data-icon="star">3</a></li> 
                    </ul>
    </div>
    </div>
 </body>
</html>

请帮帮我...... 谢谢

【问题讨论】:

  • 这个问题与 jQuery 无关,所以我取消了它的标记。你需要阅读Master Pages 因为你的Home.aspx 文件是错误的——你只需要指定headContentPlaceHolder1 部分,这里不需要&lt;html&gt; 声明

标签: asp.net


【解决方案1】:

不要在内容页面中再次使用 html、body 和 head 标签。 在 home.aspx 中,您必须像这样编写代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="home.aspx.cs" Inherits="WebApplication2.home" MasterPageFile="~/Masterpage.Master"  %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server" >
    <div data-role="page">
       <div data-role="header" data-theme="b">
       </div>
       <div data-role="content">
                    <ul data-role="listview" data-inset="true">
                    <li><a href="#" data-role="button" id="btn_group1" data-icon="heart">1</a></li>
                    <li><a href="#" data-role="button" id="btn_group2" data-icon="star">2</a></li>
                    <li><a href="#" data-role="button" id="btn_group3" data-icon="star">3</a></li> 
                        </ul>
        </div>
    </div>
</asp:content>

使用此链接http://msdn.microsoft.com/en-us/library/wtxbf3hh.ASPX

希望它会起作用。

【讨论】:

    【解决方案2】:

    在从站点嵌套的 home.aspx 中,您不能使用 &lt;head&gt;&lt;/head&gt; or &lt;body&gt;&lt;/body&gt; 您必须使用站点中定义的&lt;asp:Content&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 2023-03-14
      • 2014-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      相关资源
      最近更新 更多