这是我第一次使用Content。 我创建了一个包含所有样式等的完整aspx页面,它看起来像所有样式/引导程序等:
使用第一页作为参考,我将代码与其分离并将其复制到母版页中,并将所有导航栏代码移动到Default.aspx页面。
当我创建内容主文件并添加它所显示的代码时:
我不确定为什么造型等没有显示出来。有些东西必须组织错误吗?
我甚至尝试将css直接添加到Master中,但css仍无效。
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site1.master.vb" Inherits="CherylsGroupWeb.Site1" %>
<!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">
<title></title>
<!-- Latest compiled and minified CSS -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet"/>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet nofollow" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"/>
<!-- jQuery library -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="Index.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(document).ready(function () {
$('#menu-content li').click(function () {
$('#menu-content .active').removeClass('active'); // remove the class from the currently selected
$(this).addClass('active'); // add the class to the newly clicked link
});
</script>
<style>
<!-- put all css here to test as well -->
</style>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ContentPlaceHolder ID="topContent" runat="server">
<a href="Default.aspx">Master Pages Tutorials</a>
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="MainContent" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
答案 0 :(得分:0)
我不确定我的格式错误是什么,但是通过将示例的结构复制到一个新的Master并在我的Default.aspx周围添加内容,它会显示它。所以我为Default.aspx删除了<a>
Default.aspx的
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="GroupWeb._Default1" MasterPageFile="~/Site2.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="topContent" runat="server">
<!-- my nav bar code --->
</asp:Content>
主
<body>
<form id="form1" runat="server">
<div id='mainBody'>
<h1>
How to use Master Pages in ASP.NET
</h1>
<br />
<b>This is a Master Page Content.</b>
<br />
<br />
<div>
<asp:ContentPlaceHolder ID="topContent" runat="server">
</asp:ContentPlaceHolder>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<!-- ContentPlaceHolder is used to enable the pages which uses this page as master page, to place their contents -->
</asp:ContentPlaceHolder>
</div>
</div>
</form>
</body>