开发者

Asp.net Masterpage not working

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>

<!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>
    <link rel="stylesheet" type="text/css" href="Home.css" />
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
            <div id="banner" style="font-family: Calibri, Serif; color: #FFFFFF">
               blah blah
            </div>
        </asp:ContentPlaceHolder>开发者_StackOverflow中文版
    </div>
    </form>
</body>
</html>

Home.aspx

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Home.aspx.cs" Inherits="Home" 
MasterPageFile="~/MasterPage.master" Title="Welcome to StuartStudios!"%>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
</asp:Content>

Does Home.aspx not print whatever I define in the ContentPlaceHolder1 ? At the minute it prints nothing out. :S


When you specify markup in a ContentPlaceHolder inside of a MasterPage, that markup will only be rendered if the pages that use your master pages don't use the ContentPlaceHolder. So in Home.aspx, if you get rid of the Contact1 element, you should see your "banner" div.

So if you want your banner div to appear on ALL pages, you should move it to outside the ContentPlaceHolder control.

On your individual pages that use your master page, the Content tag should contain the stuff that's unique to the specific page.


No... ContentPlaceholder1 should be left blank in the masterpage.


I am no expert in ASP.Net, but as far as I understand the way <asp:ContentPlaceHolder /> works, when you add a <asp:Content> tag in your page file, you override the content of the ContentPlaceHolder in the master page. The contents of which will only be displayed if you do not have a corresponding Content tag.


Two things I see:

  1. Your div in your master page has color set to white. So unless I'm mistaken, you're printing white on white.
  2. Your Content item in Home.aspx IS empty, so why would it print anything else?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜