p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 4.5.1 : in C# and VB (http://p2p.wrox.com/forumdisplay.php?f=754)
-   -   Problem with basepage and template (http://p2p.wrox.com/showthread.php?t=94949)

harrija5 September 9th, 2015 08:38 PM

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

Imar September 10th, 2015 03:18 AM

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

dkeller May 1st, 2019 03:06 PM

$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.

Imar May 3rd, 2019 06:48 AM

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

dkeller May 3rd, 2019 08:48 AM

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.

dkeller May 3rd, 2019 09:45 AM

$relurlnamespace$_$safeitemname$
 
Quote:

Originally Posted by dkeller (Post 311011)
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...

Imar May 4th, 2019 07:32 AM

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

dkeller May 6th, 2019 03:20 PM

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!

Imar May 6th, 2019 03:35 PM

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?

dkeller May 6th, 2019 06:00 PM

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!


All times are GMT -4. The time now is 10:21 PM.

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