Search code examples
cssasp.netvb.netmaster-pages

Master Page doesn't grab styling for contentPlaceHolder


This is the first time I have worked with Content. I created a full aspx page with all styling and etc and it looks like this with all styling/bootstrap and etc:

enter image description here

Using the first page as a reference, I separated the code from it and copied it into the Master Page and moved all the navbar code into Default.aspx page.

When I create a content master and add the code it shows up like this:

enter image description here

I am unsure why the styling and etc doesn't show up. Something must be organized wrong?

I even tried adding css directly into the Master but still css didn't work.

<%@ 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>

Solution

  • I am not sure what exactly I formatted wrong, but by coping the structure of an example into a new Master and adding the content around my Default.aspx it displayed it. So I removed the <a> for my Default.aspx

    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>
    

    Master

    <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>