Click here to Skip to main content
15,995,080 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm running this website template using ASP.NET 3.5 (VS 2008) and, I've noticed that the content within asp:Content scrolls down to the bottom of the page, whilst I would like to write in the white space.

Also, I would like the top navigation and left navigation not to have a white space between them, is this possible?

See screenshots of site at here, and, source code is available here.

Masterpage.master
<![CDATA[<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>]]>



<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <link href="StyleSheet.css" rel="stylesheet" type="text/css" /> 
    <title>Jon's Couch</title>
    <asp:contentplaceholder id="head" runat="server" xmlns:asp="#unknown">
    </asp:contentplaceholder>
</head>
<body>
    <form id="form1" runat="server">
    </form>
       <h1>Jon's Couch</h1>
        <p style="width: 122px; height: 663px; margin-top: 0px; margin-right: 0px;">
        <a href="About.aspx">About me</a> <br />
        <a href="Diary.aspx">My diary</a> <br />
        <a href="Articles.aspx">Articles</a> <br />
        <a href="Bookmarks.aspx">My bookmarks</a> <br />
        <a href="Promotions.aspx">Promotions</a> <br />
        <a href="Resume.aspx">My resume</a> <br />
        <a href="Warez.aspx">Filesharing</a> <br />
        </p>
        <asp:contentplaceholder id="body" runat="server" xmlns:asp="#unknown">
            This page is still under construction. 
           //this shows at the bottom
        </asp:contentplaceholder>
        </body>
</html>


I've also noted that although I set the <title> tag within the master page, this does not show up within Google Chrome, or IE8. As a matter of fact no <title> tag is displayed within the HTML source of default.aspx. Is this a bug?

<html xmlns="http://www.w3.org/1999/xhtml">
<head><link href="StyleSheet.css" rel="stylesheet" type="text/css" /><title>
	Untitled Page
</title>
</head>
<body>
    <form name="aspnetForm" method="post" action="Default.aspx" id="aspnetForm">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1NDU2MTA1MmRkw9GhFk7Jm0d18GGgcCWptFrhuhY=" />
</div>
 
    </form>
       <h1>Jon's Couch</h1>
        <p style="width: 122px; height: 663px; margin-top: 0px; margin-right: 0px;">
        <a href="/KB/answers/About.aspx">About me</a> <br />
        <a href="/KB/answers/Diary.aspx">My diary</a> <br />
        <a href="/KB/answers/Articles.aspx">Articles</a> <br />
        <a href="/KB/answers/Bookmarks.aspx">My bookmarks</a> <br />
        <a href="/KB/answers/Promotions.aspx">Promotions</a> <br />
        <a href="/KB/answers/Resume.aspx">My resume</a> <br />
        <a href="/KB/answers/Warez.aspx">Filesharing</a> <br />
        </p>
        
This is my webpage, where I write about anything that sparks my interest.
The page is still under construction.
 
        </body>
</html>


I randomly :) tried adding a <title> tag within Default.aspx, however when I do this the html page crashes with the following error:

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Only Content controls are allowed directly in a content page that contains Content controls.

Source Error:

Line 1:
Line 2:
Line 3: <title>Jon's Couch

http://localhost/Jon%27s%20Couch/Default.aspx

:confused:

NOTE: Jon's Couch (ASP.NET)
Posted
Updated 17-Aug-10 2:42am
v2

1 solution

OK, following are the fixes:

1. Page Title problem:



If you use Master Pages in Asp.net, you need to set Pate title in each page's Code Behind file, instead of setting the Title in ASPX page. So, here is the things you need to do:

--Remove the following line of code from Default.aspx

<title>Jon's Couch</title>


--Add the following code in the CodeBehind of Default.aspx

C#
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Title = "Jon's Couch";
    }
}


Now you will see, page title is correctly appearing in each browser :)


2. Content scrolling down problem:




Basically, you had wrong HTML in MasterPage and Default.aspx. I have corrected those:

Corrected MasterPage code:

XML
<%@ 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">
    <link href="StyleSheet.css" rel="stylesheet" type="text/css" />
    <title>Jon's Couch</title>
</head>
<asp:contentplaceholder id="head" runat="server">
</asp:contentplaceholder>
<body>
    <form id="form1" runat="server">
    <h1>
        Jon's Couch
    </h1>
    <div style="float: left; width: 122px">
        <p style="width: 122px; height: 663px; margin-top: 0px; margin-right: 0px;">
            <a href="About.aspx">About me</a>
            <br />
            <a href="Diary.aspx">My diary</a>
            <br />
            <a href="Articles.aspx">Articles</a>
            <br />
            <a href="Bookmarks.aspx">My bookmarks</a>
            <br />
            <a href="Promotions.aspx">Promotions</a>
            <br />
            <a href="Resume.aspx">My resume</a>
            <br />
            <a href="Warez.aspx">Filesharing</a>
            <br />
        </p>
    </div>
    <div style="float: right">
        <asp:ContentPlaceHolder ID="body" runat="server">
        </asp:ContentPlaceHolder>
    </div>
    <div style="clear: both">
    </div>
    </form>
</body>
</html>



Corrected Default.aspx code:

XML
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
This is my webpage, where I write about anything that sparks my interest.
The page is still under construction.
</asp:Content>



3. Gap issue between top and left navigation:




Modify the h1 class in the StyleSheet.css as follows:

CSS
h1
{
    color:#254117;
    background-color:#4AA02C;
    text-align:right;
    font-family:Arial;
    margin:0px;
}


I just added the "margin:0px" to set the margin of h1 tag to 0px

After doing these modifications, hit ctrl+f5 to browse the Default.aspx and all your problems will be blown away.

You can have a look at a MasterPage tutorial here at CodeProject (ASP.NET 2.0 Master Pages[^])

Don't worry, Asp.net is easy. Enjoy!
 
Share this answer
 
v4
Comments
jon-80 17-Aug-10 11:12am    
Thanks :)

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