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

November 29th, 2011, 10:55 AM
|
|
Authorized User
|
|
Join Date: Feb 2011
Posts: 23
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Template Problem
I have repeatedly followed the steps starting on Page 215 "Creating a Reusable Page Template". The replacements are not being made correctly.
This is the code I put in the code behind
public partial class $relurlnamespace$_$safeitemname$ : BasePage
This is the code I put in the source
Inherits="$relurlnamespace$_$safeitemname$"
When I do Add New using the template...
The safeitemnamegets is replaced with the page name however the relurlnamespace remains unchanged.
I am doing things a bit different than the exercise...l
I am adding the page to a project not a site
My path is Solution Name - Solution Folder Name - Project Name - Page name
Do I have to do something different for it to work with projects?
|
|

November 29th, 2011, 05:45 PM
|
|
Authorized User
|
|
Join Date: Mar 2011
Posts: 74
Thanks: 21
Thanked 2 Times in 2 Posts
|
|
Creating Reusable Page Template
Quote:
Originally Posted by floridaguy
I have repeatedly followed the steps starting on Page 215 "Creating a Reusable Page Template". The replacements are not being made correctly.
This is the code I put in the code behind
public partial class $relurlnamespace$_$safeitemname$ : BasePage
This is the code I put in the source
Inherits="$relurlnamespace$_$safeitemname$"
When I do Add New using the template...The safeitemnamegets is replaced with the page name however the relurlnamespace remains unchanged.
I am doing things a bit different than the exercise...l
I am adding the page to a project not a site
My path is Solution Name - Solution Folder Name - Project Name - Page name
Do I have to do something different for it to work with projects?
|
Floridaguy:
Make sure you are seeing and selecting MyBasePage in the "Add New Item" template.
My TestPage code looks like this after following step 10 on page 217...
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Frontend.master" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="_ TestPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
</asp:Content>
I had some issues with this as well, but I think it was related to the creation of the ZIP file. After re-doing this Try It, there were 2 ZIP files, so I deleted both, went thru the Try It again from the start and all worked fine. Your issue may be related to duplicate or renamed ZIP files, but I strongly suspect it's a pathing issue since you are doing things a bit differently. Check out step 8 carefully.
Cheers and I hope this helped!
JJ
Last edited by jpjamie; November 29th, 2011 at 05:51 PM..
Reason: added "to"
|
|

November 29th, 2011, 06:17 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
You should be able to get away with just $safeitemname$ as the class name as I think the namespace is taken care off automatically (e.g. you get something like DefaultNamespace.Path.TO.Folder.
Otherwise, take a look here for some of the other template replacement parameters: http://msdn.microsoft.com/en-us/libr...v=VS.100).aspx
Hope this helps,
Imar
|
|
The Following User Says Thank You to Imar For This Useful Post:
|
|
|

November 30th, 2011, 11:38 AM
|
|
Authorized User
|
|
Join Date: Feb 2011
Posts: 23
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Inherits="UniformAdmin._$safeitemname$" %>
public partial class _$safeitemname$ : BasePage
O.K. This works but note that I had to hard code my solution name. I tried using $safeprojectname$ but that stayed unreplaced in the generated page. If I remove the solution name entirely I get...
Parser Error Message: '_RestrictDeptDate' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Interesting the page you pointed me to
http://msdn.microsoft.com/en-us/libr...v=VS.100).aspx
does not even mention relurlnamespace which you use in the book excercise.
Is this hard coded Solution name going to cause me future problems?
Quote:
Originally Posted by Imar
You should be able to get away with just $safeitemname$ as the class name as I think the namespace is taken care off automatically (e.g. you get something like DefaultNamespace.Path.TO.Folder.
Otherwise, take a look here for some of the other template replacement parameters: http://msdn.microsoft.com/en-us/libr...v=VS.100).aspx
Hope this helps,
Imar
|
Last edited by floridaguy; November 30th, 2011 at 11:41 AM..
|
|

December 1st, 2011, 10:20 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
>> Is this hard coded Solution name going to cause me future problems?
Yes, as the template is now tied to the solution and therefore less reusable.
However, for Web Forms you don't have to do anything. Try this:
1. Add a new standard Web Form
2. Leave names, classes, namespaces etc as they are.
3. Add some stuff. For example, a control in the markup or a method in the code behind
4. Export the template.
5. Create a new web form based on this template.
It should just work and VS should take care of file names and class names.
Cheers,
Imar
|
|

December 2nd, 2011, 02:14 PM
|
|
Authorized User
|
|
Join Date: Feb 2011
Posts: 23
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Yes This does work! I had to remember to change the inheritance to BasePage but that was it. When would the more complex instructions in the book be useful?
Quote:
Originally Posted by Imar
>> Is this hard coded Solution name going to cause me future problems?
Yes, as the template is now tied to the solution and therefore less reusable.
However, for Web Forms you don't have to do anything. Try this:
1. Add a new standard Web Form
2. Leave names, classes, namespaces etc as they are.
3. Add some stuff. For example, a control in the markup or a method in the code behind
4. Export the template.
5. Create a new web form based on this template.
It should just work and VS should take care of file names and class names.
Cheers,
Imar
|
|
|

December 4th, 2011, 06:22 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Quote:
|
When would the more complex instructions in the book be useful?
|
When doing a Web Site Project as used in the book for example. The standard export feature doesn't take the folder structure into account with a Web Site Project so you can end up with two separate pages (called Default.aspx in two different folders for example), sharing the same code behind class. This isn't a problem when running the site from VWD, but it gets problematic when you try to precompile your application.
Cheers,
Imar
|
|
 |
|