Build Your Own ASP.NET 4 Website problem


I was given a copy of this book by a friend in order to get me up to scratch on ASP.NET. So far I’ve created a new ASP.NET Web Site using Visual C# and saved it in “C:\LearningASP\CS\”

Now I’m on page 14 chapter one were the book states:

The main panel in the Visual Web Developer interface is the page editor, in which you’ll see the HTML source of the Default.aspx web page. Edit the title of the page to something more specific than Home Page, such as Welcome to Build Your Own ASP.NET 4 Website!:

<html xmlns="">
  <head runat="server">
    [B]<title>Welcome to Build Your Own ASP.NET 4 Website!

The book’s bold type implies that this is code we are editing rather than an entire new piece of code however in Default.aspx there isn’t any <html> tags present. My Default.aspx looks like this:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        Welcome to ASP.NET!
        To learn more about ASP.NET visit <a href="" title="ASP.NET Website"></a>.
        You can also find <a href=";clcid=0x409"
            title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.

But the book implies that I am editing a title tag within html tags that already exist with “Home Page” as the content, I can’t find this anywhere in the project. So I tried replacing the entire Default.aspx file with the code in the book but then the output differs from figure 1.12.

The code included with the book is different again:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
  <head runat="server">
    <title>Welcome to Build Your Own ASP.NET 3.5 Web Site!</title>
    <form id="form1" runat="server">
      <p>Hello there!</p>
        The time is now:
        <asp:Label ID="myTimeLabel" runat="server" />

There’s no instruction to strip down the header from:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>


<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

Note: I’m using Visual Studio 2010 and not Visual Studio Web Express.

The difference is that the first example (snippets 1 and 2) demonstrates using a master page to define common layout, and using a content only page for the actual content. In such a case, the default title is within the master pages title element in the head element. This is overridden in the comsuming content page by the title=“something” attribute in the @PAGE directive at the top. The second example (the one you created) is an example of a content page, with no master: it does everything, and the @PAGE directives change. Some attributes are no longer required, such as which master page it’s using. I hope that helps.

That does help. But I think that means the book is wrong.

When you create a website in Visual Studio you have two options: ASP.NET Website and ASP.NET Empty Website.

ASP.NET Website will give you a basic template to get started. It’ll have a master page file, some content pages, some login pages, style sheets and whatever else. The Empty Website won’t have that… all it has is a web.config file and it is the developers task to create each file needed for the page.

The other possibility is you’re missing something from earlier in the book? A lot of development books have some code files that can be downloaded from the web or pulled from an accompanying CD… in which case you might find the files they’re referring to in the state they’re in. I don’t know for sure since I don’t have that book but I’d read everything BEFORE chapter one (if you haven’t) and see if it references this.

Book probably isn’t wrong here – the defaults changed a bit. Using a different version of Visual Studio don’t help.

I’m having this exact problem. Has anyone found a solution? I’m using the software the book suggested, but still it won’t work. It does, however, allow me to produce myTimeLabel in a browser if I use script instead of code-behind.

I have the same problem, I get a syntax error with “Handles Me.Load”. I have Visual Studio Web Developer 2012 and .NET 4.5

Is there a forum thread other than this for errors/corrections/updates to the book?

AFAIK every SitePoint book has a “corrections” or errata page. The one for this book is though not much help at present I’m afraid.

Corrections and Typos

No known errors at this time

I removed the carriage returns and the page ran. (I’m actually a ColdFusion developer, and CF ignores whitespace, but overnight I remembered something about other languages not being so generous. CF rocks, btw.) To be fair, the book has that little continue arrow dealeo but I didn’t see it.

So mine looks like this:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
myTimeLabel.Text = DateTime.Now.ToString()
End Sub