 |
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|
|

March 13th, 2013, 03:08 PM
|
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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.
|
|

March 13th, 2013, 03:20 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

March 13th, 2013, 09:35 PM
|
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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 10:25 PM..
|
|

March 14th, 2013, 10:05 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

March 14th, 2013, 10:23 AM
|
|
Authorized User
|
|
Join Date: Jun 2012
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
|
|
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
|
|

March 14th, 2013, 10:25 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|
 |
|