Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 13th, 2013, 04:08 PM
Authorized User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default MyBasePage template has freaky errors

Hi Imar!

I'm following the Try-It-Out exercises in the book (I love your book, btw), and when I go to use the MyBasePage template I created (twice) in Chapter 6 (Pages 210-212), I get the following error: 'Context' is not a member of '_TestPage'. VWD underlines the directive at the very top as the offending code. Below is my markup for TestPage.aspx:

Code:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="false" CodeFile="TestPage.aspx.vb" Inherits="_TestPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
</asp:Content>
And here is the code behind TestPage.aspx.vb:

Code:
Partial Class TestPage
		Inherits BasePage

End Class
Finally, the code for BasePage.vb:

Code:
Public Class BasePage
  Inherits System.Web.UI.Page

  Private Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) _
      Handles Me.PreInit
    Dim preferredTheme As HttpCookie = Request.Cookies.Get("PreferredTheme")
    If preferredTheme IsNot Nothing Then
      Page.Theme = preferredTheme.Value
    End If
  End Sub
  Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
    If Me.Title = "Untitled Page" Or String.IsNullOrEmpty(Me.Title) Then
      Throw New Exception("Page title cannot be ""Untitled Page"" or an empty string.")
    End If
  End Sub

End Class
Where the heck is VWD getting this 'Context' thing from?

I really hope you can help me. I did this exercise multiple times and followed the book down to the letter. What could I have done wrong? Any help is greatly appreciated.
Reply With Quote
  #2 (permalink)  
Old March 13th, 2013, 04:20 PM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Hi there,

Take a look at this:

Code:
Inherits="_TestPage"
and this:

Code:
Partial Class TestPage
There's an underscore missing in the code behind class.

Based on the Markup and Code Behind, .NET creates a new file under the hood. That may have a reference to Context but it breaks somehow because of the mismatch between Markup and Code Behind.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
GreenhornPup (March 13th, 2013)
  #3 (permalink)  
Old March 13th, 2013, 10:35 PM
Authorized User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you, Imar!

Now, on the Try-It-Out on p.253-255 in Chapter 7, I have to tweak my markup and my code behind. For example, in the new folder called Reviews and its files called "Default.aspx" and "All.aspx", the Inherits clause in the directive points to "Reviews_Default and Reviews_All, respectively. I have to delete the "Reviews" from it so it will say "_Default" or "_All", as well as add an underscore to "Default" and "All" in the code behind. Given valid titles, they both work awesome. Is this normal, or have I done something wrong somewhere else that would cause me to have to do the tweaking?

Nevermind, lol, I've got it working now. I just went back and redid p. 215-217, and it's working great so far. Thank you so much for your help. If I need anything else, I'll holler.

GreenhornPup

Last edited by GreenhornPup; March 13th, 2013 at 11:25 PM.
Reply With Quote
  #4 (permalink)  
Old March 14th, 2013, 11:05 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Yeah, I was just going to recommend that. If you create the template as designed, new pages work as intended, and you don't have to manually change anything.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old March 14th, 2013, 11:23 AM
Authorized User
Points: 45, Level: 1
Points: 45, Level: 1 Points: 45, Level: 1 Points: 45, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Imar, I have another problem now. The MyBasePage template keeps disappearing from the menu when I click "add new item". I use both VB and C#, and therefore have separate folders for each. I still have the MyBasePage for VB, but the one for C# keeps disappearing, even after it worked so beautifully for me last night when I re-created it. And yes, when I imported it, I did specify C# as the language. Why did it disappear, and will I have to keep creating the same template over and over if I want to use MyBasePage for C#? Your help is greatly appreciated.

GreenhornPup
Reply With Quote
  #6 (permalink)  
Old March 14th, 2013, 11:25 AM
Imar's Avatar
Wrox Author
Points: 71,164, Level: 100
Points: 71,164, Level: 100 Points: 71,164, Level: 100 Points: 71,164, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,955
Thanks: 79
Thanked 1,556 Times in 1,533 Posts
Default

Did you rename the ZIP file in the template folder after you created the first template as recommended in the book? If they have same name, the second one overwrites the first one.

I have both templates show up at the same time (that is, the C# version in the C# site and the VB version in the VB site) so it's definitely possible.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
template uicdbd XSLT 1 March 14th, 2007 06:16 PM
calling one template in other template VijayKumar XSLT 3 September 15th, 2005 12:12 PM
Can't get errors to display with <html:errors> michaeldill JSP Basics 0 August 2nd, 2004 02:47 PM
errors and fixing errors Droopy XML 0 August 26th, 2003 01:47 AM
Errors Errors DB Errors Ljhopkins VS.NET 2002/2003 0 July 15th, 2003 01:42 PM



All times are GMT -4. The time now is 07:24 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.