2017-06-03 9 views
0

申し訳ありません。私はVisual Web Developerを使って学校プロジェクトを作っています。私はマスターページを使う必要があります。マスターページに基づいて新しいWebフォームを作成すると、マスターページの色が継承されますが、継承されていないテーブルがあります。ここに私のマスターページのコードは次のとおりです。Webフォームが継承していないMicrosoft Visual Studioのマスターページ

<%@ Master Language="VB" CodeFile="Master1.master.vb" Inherits="Master1" %> 

    <!DOCTYPE html> 

    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head runat="server" background-color: #00FF00;> 
     <title></title> 
     <asp:ContentPlaceHolder id="head" runat="server"> 
     </asp:ContentPlaceHolder> 
     <style type="text/css"> 
      .auto-style2 { 
       height: 57px; 
       width: 2363px; 
      } 
      .auto-style3 { 
       height: 57px; 
       width: 48px; 
      } 
      .auto-style4 { 
       height: 48px; 
      } 
      .newStyle1 { 
       background-color: #FF00FF; 
      } 
      .auto-style5 { 
       width: 369px; 
       height: 214px; 
      } 
     </style> 
    </head> 
    <body style="background-color: blue;"> 
     <form id="form1" runat="server"> 
     <div class="newStyle1"> 
      <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server"> 

       <table class="newStyle1"> 
        <tr> 
         <td class="auto-style4" colspan="2"> 
          <asp:Menu ID="Menu1" runat="server" Orientation="Horizontal"> 
           <Items> 
            <asp:MenuItem NavigateUrl="Default.aspx" Text="Home" Value="Home"></asp:MenuItem> 
            <asp:MenuItem NavigateUrl="About.aspx" Text="About" Value="About"></asp:MenuItem> 
           </Items> 
          </asp:Menu> 
         </td> 
        </tr> 
        <tr> 
         <td class="auto-style3"> 
          <img alt="CS Logo" class="auto-style5" src="cSk.png" /></td> 
         <td class="auto-style2"> 
          <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server"> 
          </asp:ContentPlaceHolder> 
         </td> 
        </tr> 
        <tr> 
         <td class="auto-style4" colspan="2"></td> 
        </tr> 
       </table> 

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

マスターページVBコード:

Partial Class Master1 
    Inherits System.Web.UI.MasterPage 
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load 

    End Sub 
End Class 



Web Form Attempted to Inherit Master Page: 

%@ Page Title="" Language="VB" MasterPageFile="~/Master1.master" %> 

<script runat="server"> 

</script> 

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

Master Page

+0

スクリプトを 'ContentPlaceHolderID =" head "'に入れてみてください。 – wazz

+1

ありがとうございます。 divの外側にテーブルを動かすことで、私自身の問題を解決しました。 –

答えて

1

あなたはこのコンテンツを上書きしたい場合のみ、マスターページ内のプレースホルダ内のHTML要素を配置する必要があります次の子ページに表示されます。

子ページの問題は、テーブルを含むプレースホルダが空のHTMLで上書きされることです。

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> </asp:Content>

あなたがコンテンツを継承したい場合は、プレースホルダで共有コンテンツを置かないでください。

共有コンテンツをプレースホルダに配置するこの方法を採用する必要がある場合は、このコンテンツを子ページに上書きしないでください。だからあなたの例では:

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> </asp:Content>

は、マスターページでテーブルを表示していました。

希望に役立ちます。

関連する問題