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.5.1 > BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 4.5.1 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4.5.1: in C# and VB by Imar Spaanjaars; ISBN: 978-1-118-84677-3
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4.5.1 : 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 Search this Thread Display Modes
  #1 (permalink)  
Old September 9th, 2015, 08:38 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2015
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with basepage and template

I have created a base page and the associated template, when sending to ie I get the following VS errors:
1. $relurlnamespace&_&safeitemname$ is not a valid value for attribute 'inherits'

2. Character is not valid


Here are the contents of the basepage.vb and temporary.aspx.vb:

------------------------------------------------------
basepage.vb

Imports Microsoft.VisualBasic

Public Class BasePage
Inherits System.Web.UI.Page
Private Sub Page_PreRender(sender As Object, e As EventArgs) Handles Me.PreRender
If String.IsNullOrEmpty(Me.Title) OrElse Me.Title.Equals("Untitled Page",
StringComparison.CurrentCultureIgnoreCase) Then
Throw New Exception(
"Page title cannot be ""Untitled Page"" or an empty string.")
End If
End Sub
End Class
----------------------------------------------
temporary.aspx.vb

Partial Class $relurlnamespace$_$safeitemname$

Inherits BasePage
End Class

I noticed that in the temporary.aspx.vb file the leading $ shows character not valid.

Thank you for your assistance.

JIm
Reply With Quote
  #2 (permalink)  
Old September 10th, 2015, 03:18 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Hi Jim,

The Temporary.aspx page is just that: temporary. It won't run as-is but it serves only to be exported as a template as described in the book (looks like you missed, or haven't carried out this step). Once you've exported the template you can create new pages using this template using the Add New Item dialog.

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
  #3 (permalink)  
Old May 1st, 2019, 03:06 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2018
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default $relurlnamespace$_$safeitemname$

I am also a newbie and I am seeing the same problem when I rename the class from Temporary to $relurlnamespace$_$safeitemname$.

In case I read something wrong, I opened the file downloaded from the WROX website and Visual Studio shows the red squiggle under the above text in that file as well. This is AFTER I did all of the steps.

When I viewed the source of the TestPage on my website, instead of the title showing as
_TestPage
it showed as
$relurlnamespace$_TestPage

I don't know if that helps you figure out what was wrong or not.
Reply With Quote
  #4 (permalink)  
Old May 3rd, 2019, 06:48 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

This is by design. $relurlnamespace$_$safeitemname$ is not a valid identifier in C# so the temporary page is just that: temporary. It serves purely to create a template out of it. Once the template has been created you should delete the Temporary.aspx page again.

When you add a new web form based on the template, Visual Studio will replace $relurlnamespace$_$safeitemname$. with the new, safe, name of the page you're adding.

Does that help?

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 May 3rd, 2019, 08:48 AM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2018
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am still getting an error using the beginning "global" symbol (the first text enclosed in dollar signs). And unfortunately, later exercises build on the basepage, so I have to develop a workaround.
Reply With Quote
  #6 (permalink)  
Old May 3rd, 2019, 09:45 AM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2018
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default $relurlnamespace$_$safeitemname$

Quote:
Originally Posted by dkeller View Post
I am still getting an error using the beginning "global" symbol (the first text enclosed in dollar signs). And unfortunately, later exercises build on the basepage, so I have to develop a workaround.
When I use the basepage, the first symbol in the dollar signs appears as I have it in the template. The compiler does not substitute. I also noticed in the post on your website that the person who gave you the fix mentioned that it may not work for others without the same advanced settings.
I must be doing something wrong because I have an error that my message is too short...
Reply With Quote
  #7 (permalink)  
Old May 4th, 2019, 07:32 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Can you be a bit more specific about where you get the error exactly? On which page(s) do you get the error? Maybe you can post a screenshot somewhere showing Visual Studio with the page and offending code?

Also, make sure you created the custom template correct;y. To verify, locate it under your Documents (it's a zip somewhere in the Visual Studio folder) and look at the files in the archive. Do they contain what is needed? Posting the code from those template files would also help.

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
  #8 (permalink)  
Old May 6th, 2019, 03:20 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2018
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When I use the template to create a new webpage (I called it TesterPage.aspx), it looks like this:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Frontend.Master" AutoEventWireup="true" CodeBehind="TesterPage.aspx.cs" Inherits="$relurlnamespace$_TesterPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="server">
<p>
</p>
</asp:Content>

You can see in the Inherits attribute that Visual Studio has
Inherits="$relurlnamespace$_TesterPage"
which then gives me further errors.

Is there a setting that I am missing? I copied the code for the base page out of the source files, so there shouldn't be a typo causing the problem.

The Temporary file I used to create the template contains the following code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dkwebapp1
{
public partial class $relurlnamespace$_$safeitemname$ : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}

(I changed my project name to dkwebapp1 as this is my second time trying to use this book...)

Please shed some light on what it is that I have done wrong! Thanks!
Reply With Quote
  #9 (permalink)  
Old May 6th, 2019, 03:35 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

And how does the markup of the template look? You showed an error with the markup, but posted the code for the code behind. Maybe there's something wrong in the markup of the template?
__________________
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
  #10 (permalink)  
Old May 6th, 2019, 06:00 PM
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2018
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is the template:

template.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Frontend.Master" AutoEventWireup="true" CodeBehind="Template.aspx.cs" Inherits="$relurlnamespace$_$safeitemname$" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="server">
</asp:Content>

Code behind, Template.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dkwebapp1
{
public partial class $relurlnamespace$_$safeitemname$ : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}
Once I created the "Template" template, I closed and re-opened VS, then added a page called, "NewPage.aspx":

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Frontend.Master" AutoEventWireup="true" CodeBehind="NewPage.aspx.cs" Inherits="$relurlnamespace$_NewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" runat="server">
</asp:Content>

and its code behind file contains the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace dkwebapp1
{
public partial class $relurlnamespace$_NewPage : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}
}

From what I can see, the first template parameter, $relurlnamespace$ has not been replaced with any valid text, and therefore, I get many errors when I try to open it in a browser. First CS1001, Identifier expected, then CS1514, { expected, then CS1513, } expected, then CS1056, Unexpected character '$', then CS0116 A namespace annot directly ontain members such as fields or methods.....

Does this give you enough info to help me? (I hope so! - I am very frustrated!!)

Here is the MyTEmplate.vstemplate file from the Zip file too:

<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Item">
<TemplateData>
<DefaultName>Template.aspx</DefaultName>
<Name>Template</Name>
<Description>Trying to figure out issue</Description>
<ProjectType>CSharp</ProjectType>
<SortOrder>10</SortOrder>
<Icon>__TemplateIcon.ico</Icon>
</TemplateData>
<TemplateContent>
<References />
<ProjectItem SubType="" TargetFileName="$fileinputname$.aspx" ReplaceParameters="true">Template.aspx</ProjectItem>
<ProjectItem SubType="Code" TargetFileName="$fileinputname$.aspx.cs" ReplaceParameters="true">Template.aspx.cs</ProjectItem>
<ProjectItem SubType="" TargetFileName="$fileinputname$.aspx.designer.cs" ReplaceParameters="true">Template.aspx.designer.cs </ProjectItem>
</TemplateContent>
</VSTemplate>

Thank you for your help!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Chapter 6 BasePage Darkryder007 BOOK: Beginning ASP.NET 4.5 : in C# and VB 8 April 4th, 2015 04:04 AM
Chapter 6 BasePage & Template Try It Out PhilC BOOK: Beginning ASP.NET 4 : in C# and VB 7 April 4th, 2013 02:54 PM
Basepage Khalil BOOK: Beginning ASP.NET 4 : in C# and VB 3 December 7th, 2011 06:42 AM
BasePage Question Rushino BOOK: Beginning ASP.NET 4 : in C# and VB 9 April 9th, 2010 12:48 PM
Reference to BasePage member4953 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 March 27th, 2009 01:45 PM



All times are GMT -4. The time now is 06:04 PM.


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