Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

Each time I build my MasterPage.master.aspx, I get an error that reads:

The type 'MasterPage2' already contains a definition for 'head'
This error appears for all the protected values in my MasterPage.master.cs file. How do I fix the error please?

Below is my MasterPage.master.aspx codes:
C#
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage2" %>
<!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>Untitled Page</title>
    <link href="css/Style.css" rel="stylesheet" type="text/css" media="all" />   
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1"  runat="server">
    <div id="container">
        <!--header starts -->
        <div id="header">
            <div id="logo">
                <img  src="~/Images/logo.gif" alt="logo"  runat="server" /></div>
            <div id="logoright">
                <div id="topbar1" style="float: right">
                    <div class="empty" style="padding-removed3px; padding-removed 10px; background: #f1f1f1; height: 25px">
                      <a id="A1" href="~/Agent_list.aspx"  runat="server">Agents</a>|  <a href="~/AboutUs.aspx"  runat="server">About Us</a>|  <a id="A2" href="~/Faq.aspx"  runat="server" >FAQ</a>|  <a id="A9" href="~/Feedback.aspx"  runat="server">Feedback</a>| 
                        <a href="~/contactus.aspx"  runat="server">Contact Us</a></div>
                    <div class="empty" style="background: #f1f1f1">
                    
                        <img height="25" alt="" src="~/Images/top_curve2.gif" width="32"   runat="server" /></div>
                    <div class="empty" style="width: auto; height: 25px; text-align: center">
                    </div>
                </div>
                <div class="empty" style="float: right; margin: 9px 0px 8px; ">
                    <img height="56" alt="" src="~/Images/paper.gif" width="286"   runat="server" /><asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" 
                            ShowStartingNode="False" />
                            </div>
                <div id="navigation"> 
                <div>
                <asp:Menu ID="MainMenu" runat="server" Orientation="Horizontal" MaximumDynamicDisplayLevels="0"
                DataSourceID="SiteMapDataSource1" DynamicEnableDefaultPopOutImage="False" StaticEnableDefaultPopOutImage="False">
                <StaticMenuStyle CssClass="menu" />
                <StaticMenuItemStyle CssClass="menuItem" />
                <StaticSelectedStyle CssClass="menuSelectedItem" />
                <DynamicMenuStyle CssClass="menuPopup" />
                <DynamicMenuItemStyle CssClass="menuPopupItem" Font-Strikeout="False" />
                <DynamicHoverStyle CssClass="menuPopupItem" />
                <StaticHoverStyle CssClass="menuItemHover" />
            </asp:Menu>
                </div>
            <div id="submenu"  runat="server">
            <ul id="submenulist">
            <li><a id="home" href="~/AdminArea/HomeForAdmin.aspx"  runat="server">Basic Info</a></li>
             <li><a id="A3" href="~/AdminArea/CreateAgent.aspx"  runat="server">Create Agent</a></li>
              <li><a id="A4" href="~/AdminArea/All_Agents_info.aspx"  runat="server">Agent List</a></li>
               <li><a id="A5" href="~/AdminArea/Deposit.aspx"  runat="server">Deposite</a></li>
               <li><a id="A6" href="~/AdminArea/Agent_search.aspx"  runat="server">Search Agent</a></li>
              <li><a id="A7" href="~/AdminArea/Bus_list.aspx"  runat="server">Bus List</a></li>
               <li><a id="A8" href="~/AdminArea/feedback_list.aspx"  runat="server">FeedBack List</a></li>
            </ul>
            </div>
             </div>
            </div>
        </div>
        <div>
            <table style="width: 100%;">
                <tr>
                    <td colspan="3">
                        <asp:ScriptManager ID="ScriptManager1" runat="server" />
                            <asp:UpdatePanel ID="up12" runat="server">
                            <ContentTemplate>
                                <table cellspacing="0" cellpadding="0" width="100%" border="0">
                                    <tbody>
                                        <tr>
                                            <td class="border-header" style="height: 25px;" valign="middle"
                                                align="left" width="600">
                                                Welcome <asp:LoginName ID="LoginName1" runat="server" />, Rs.<asp:Literal ID="litbal" runat="server" />
                                            </td>
                                            <td class="border-header-date" style="height: 25px" valign="middle" align="left"
                                                width="200">
                                                <asp:Literal ID="litdate" runat="server"></asp:Literal>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </ContentTemplate>
                        </asp:UpdatePanel>
                        <asp:ContentPlaceHolder ID="content1" runat="server">
                        </asp:ContentPlaceHolder>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
                        </asp:ContentPlaceHolder>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <asp:ContentPlaceHolder ID="ContentPlaceHolder3" runat="server">
                        </asp:ContentPlaceHolder>
                    </td>
                </tr>
                <tr>
                    <td colspan="3">
                        <asp:ContentPlaceHolder ID="ContentPlaceHolder4" runat="server">
                        </asp:ContentPlaceHolder>
                    </td>
                </tr>
                <tr>
                    <td>
                         
                    </td>
                    <td>
                         
                    </td>
                    <td>
                         
                    </td>
                </tr>
            </table>
        </div>
        
            <div id="footer">
                <div id="footerlinks">
                    <div style="float: left">
                       Copyright © 2010, All rights reserved   <span class="orange11">l</span>   <a href="~/Privacypolicy.aspx"   runat="server">Privacy policy</a>  <span class="orange11">
                            l</span>   <a href="~/TermsandConditions.aspx"   runat="server">Terms and conditions</a> 
                        <br />
                    </div>
                    <div style="float: right; text-align: right">
                       <asp:Label ID="lblCreatedBy" runat="server"></asp:Label>  
                    </div>                    
                </div>                
            <!--footer ends -->
            <div>
                <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                </asp:ContentPlaceHolder>
            </div>
            </div>
        </div> 
    </form>
</body>
</html>

And here is my MasterPage.master.cs code:
C#
using System;
using System.Web;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class MasterPage2 : System.Web.UI.MasterPage
{

    protected ContentPlaceHolder head;
    protected HtmlAnchor A1;
    protected HtmlAnchor A2;
    protected HtmlAnchor A9;
    protected SiteMapDataSource SiteMapDataSource1;
    protected Menu MainMenu;
    protected HtmlAnchor home;
    protected HtmlAnchor A3;
    protected HtmlAnchor A4;
    protected HtmlAnchor A5;
    protected HtmlAnchor A6;
    protected HtmlAnchor A7;
    protected HtmlAnchor A8;
    protected HtmlGenericControl submenu;
    protected ScriptManager ScriptManager1;
    protected LoginName LoginName1;
    protected Literal litbal;
    protected Literal litdate;
    protected UpdatePanel up12;
    protected ContentPlaceHolder content1;
    protected ContentPlaceHolder ContentPlaceHolder2;
    protected ContentPlaceHolder ContentPlaceHolder3;
    protected ContentPlaceHolder ContentPlaceHolder4;
    protected Label lblCreatedBy;
    protected ContentPlaceHolder ContentPlaceHolder1;
    protected HtmlForm form1;
    protected DefaultProfile Profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }

    protected HttpApplication ApplicationInstance
    {
        get
        {
            return this.Context.ApplicationInstance;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.litdate.Text = DateTime.Now.ToString("D");
        if (((object)this.Page.User.Identity.Name).ToString() != "")
            this.litbal.Text = DB.ExecuteScaler(string.Format("Select Agent_current_bal from AgentBasicInfo where Agent_ID='{0}'", (object)((object)this.Page.User.Identity.Name).ToString().ToLower())).ToString();
        else
            this.up12.Visible = false;
        this.submenu.Visible = ((object)this.Page.User.Identity.Name).ToString() == "admin";
        this.lblCreatedBy.Text = "Created By: otieno t oloo";
    }
}
Posted

1 solution

Look at your code:
ASP.NET
<asp:contentplaceholder id="head" runat="server" xmlns:asp="#unknown"></asp:contentplaceholder>

And
C#
protected ContentPlaceHolder head;

Now, isn't it obvious why it's complaining? :laugh:
 
Share this answer
 
Comments
tancliffe 5-Jul-14 10:04am    
Would you kindly explain to me what this code means please if you don't mind?
<asp:contentplaceholder id="head" runat="server" xmlns:asp="#unknown">
tancliffe 5-Jul-14 12:33pm    
if I change and use the code above, I get this error:
Parser Error Message: Type 'System.Web.UI.WebControls.ContentPlaceHolder' does not have a public property named 'xmlns:asp'.
tancliffe 6-Jul-14 10:51am    
Any help plz?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900