Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3
This is the forum to discuss the Wrox book Beginning ASP.NET 3.5: In C# and VB by Imar Spaanjaars; ISBN: 9780470187593
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 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 December 19th, 2008, 12:42 AM
Friend of Wrox
Points: 505, Level: 8
Points: 505, Level: 8 Points: 505, Level: 8 Points: 505, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2008
Location: , , .
Posts: 119
Thanks: 26
Thanked 0 Times in 0 Posts
Default p 213

Hi Imar:

I'm not sure I'm doing this right. After exporting the "MyBasePage" as instructed, I do see it now in the template region under My Templates.

But when I add a new page by right clicking on my website name and choosing Add new item, and adding a new page called TestPage.aspx, the page's title is TestPage. But it doesn't inherit from BasePage.

In the page's source view it inherits from TestPage:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" %>

And in the Code Behind file it inherits from System.Web.UI.Page:

public partial class TestPage : System.Web.UI.Page

Is that what the test page file is supposed to state?

Was I suppose to click on the MyBasePage when I added the page and named it TestPage?

Rachel

Last edited by Rachel; December 19th, 2008 at 12:59 AM..
Reply With Quote
  #2 (permalink)  
Old December 19th, 2008, 02:48 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Sounds like you forgot to change the classname in the code behind file.... Or maybe you didn't save that file before you exported the template and only saved the .aspx?

You should have Inherits BasePage in the Code Behind as well...

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 December 19th, 2008, 10:01 PM
Friend of Wrox
Points: 505, Level: 8
Points: 505, Level: 8 Points: 505, Level: 8 Points: 505, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2008
Location: , , .
Posts: 119
Thanks: 26
Thanked 0 Times in 0 Posts
Default

I'm re-doing it.

On page 210 in the try it out, I wasn't sure the first time I did this and am still not sure now as I do it again, what you mean there by making sure it... "is based on the master page in the MasterPages folder".

What I am doing is :

I right click my website c:\BegASPNET\WebSite1\, then "Add new item", then choose "Web Form", name it Template.aspx, and make sure both the check boxes are checked for code behind and "Select Master Page"?

Is that correct?

Rae
Reply With Quote
  #4 (permalink)  
Old December 19th, 2008, 10:28 PM
Friend of Wrox
Points: 505, Level: 8
Points: 505, Level: 8 Points: 505, Level: 8 Points: 505, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2008
Location: , , .
Posts: 119
Thanks: 26
Thanked 0 Times in 0 Posts
Default

After re-doing, I end up with the same file info in the test page added after exporting the MyBasePage file:

From Testpage's aspx file:

<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="TestPage.aspx.cs" Inherits="TestPage" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMainContent" Runat="Server">
my optional comments .
</asp:Content>

----------------------------------
from code behind (aspx.cs) file:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class TestPage : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{

}
}

---------

I made sure I "saved all". I clicked the Save All button at top of my menu couple of times to be sure and saved the page individually as well before exporting it.

Rachel
Reply With Quote
  #5 (permalink)  
Old December 19th, 2008, 10:30 PM
Friend of Wrox
Points: 505, Level: 8
Points: 505, Level: 8 Points: 505, Level: 8 Points: 505, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2008
Location: , , .
Posts: 119
Thanks: 26
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Imar View Post
Sounds like you forgot to change the classname in the code behind file.... Or maybe you didn't save that file before you exported the template and only saved the .aspx?

You should have Inherits BasePage in the Code Behind as well...

Imar
I've got it in the code behind, but not in the aspx file.

Also, I did change the class name from Template to $safeitemname$ .
Reply With Quote
  #6 (permalink)  
Old December 20th, 2008, 06:15 AM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

The final code you posted looks exactly as it should, doesn't it?

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
  #7 (permalink)  
Old December 20th, 2008, 12:16 PM
Friend of Wrox
Points: 505, Level: 8
Points: 505, Level: 8 Points: 505, Level: 8 Points: 505, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2008
Location: , , .
Posts: 119
Thanks: 26
Thanked 0 Times in 0 Posts
Default

Oh, ok. I thought when you said "You should have Inherits BasePage in the Code Behind as well..."
that I should have had "inherits : BasePage" instead of "inherits : TestPage" in the .aspx file as well.

So it is okay I guess.


Thanks,
Rachel
Reply With Quote
  #8 (permalink)  
Old December 20th, 2008, 12:57 PM
Imar's Avatar
Wrox Author
Points: 72,073, Level: 100
Points: 72,073, Level: 100 Points: 72,073, Level: 100 Points: 72,073, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

Heuh? The Code Behind is just that: the (nested) code file that sits behind the .aspx file.

The book uses "Code Behind" to refer to the code behind, and Markup View to refer to the "code before" of the ASPX page.

Furthermore, the Code Behind class inherits from BasePage. The "code before" class in turn inherits from this class (like TestPage) defined in Code Behind.

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
  #9 (permalink)  
Old December 23rd, 2008, 11:05 AM
Friend of Wrox
Points: 505, Level: 8
Points: 505, Level: 8 Points: 505, Level: 8 Points: 505, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2008
Location: , , .
Posts: 119
Thanks: 26
Thanked 0 Times in 0 Posts
Default

Thanks Imar.
That makes it a little clearer for me.

Rachel
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




All times are GMT -4. The time now is 08:17 PM.


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