SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Build Your Own ASP.NET 4 Website problem

    Hello,

    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!:
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
        <title>Welcome to Build Your Own ASP.NET 4 Website!
    </title>
    </head>
    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:

    Code:
    <%@ 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>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <h2>
            Welcome to ASP.NET!
        </h2>
        <p>
            To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
        </p>
        <p>
            You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&amp;clcid=0x409"
                title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
        </p>
    </asp:Content>
    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:

    Code:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!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>Welcome to Build Your Own ASP.NET 3.5 Web Site!</title>
      </head>
      <body>
        <form id="form1" runat="server">
        <div>
          <p>Hello there!</p>
          <p>
            The time is now:
            <asp:Label ID="myTimeLabel" runat="server" />
          </p>
        </div>
        </form>
      </body>
    </html>
    There's no instruction to strip down the header from:

    Code:
    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeFile="Default.aspx.cs" Inherits="_Default" %>
    To:
    Code:
    <%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
    Note: I'm using Visual Studio 2010 and not Visual Studio Web Express.

  2. #2
    Resident OCD goofball! bronze trophy Serenarules's Avatar
    Join Date
    Dec 2002
    Posts
    1,911
    Mentioned
    26 Post(s)
    Tagged
    0 Thread(s)
    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.

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That does help. But I think that means the book is wrong.

  4. #4
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ashleyconnor View Post
    Hello,

    Note: I'm using Visual Studio 2010 and not Visual Studio Web Express.
    Book probably isn't wrong here -- the defaults changed a bit. Using a different version of Visual Studio don't help.

  6. #6
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  7. #7
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by natehood View Post
    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?

  8. #8
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,253
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    AFAIK every SitePoint book has a "corrections" or errata page. The one for this book is http://www.sitepoint.com/books/aspnet4/errata.php though not much help at present I'm afraid.
    Corrections and Typos

    No known errors at this time

  9. #9
    SitePoint Member
    Join Date
    Jul 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Solved, at least for me

    Quote Originally Posted by rknutson View Post
    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
    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


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •