Wrox Programmer Forums
|
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 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
 
Old March 10th, 2009, 12:15 PM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 194
Thanks: 5
Thanked 3 Times in 3 Posts
Default

Ok thanks.

Sorry about delayed reply currently decorating and haven't had access to the internet for a couple of days.
 
Old January 22nd, 2010, 03:53 PM
Registered User
 
Join Date: Jan 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default Master Pages vs Base Pages

I understand what you are saying here, but still am a bit confused.

master pages have code behind that allows them to execute functionality, and Content Pages also have code behind that executes functionality. Why can't functionality created on a master page not be called directly from the base page.

example. a master page that contains an ErrorSummary Control & a custom ErrorControl. The code behind has a virtual method to Show errors in the afore mentioned controls. My Content page doesn't see these methods and cannot ovverride them.

I can create a base page that can find the control then implement the method, but that seems so much more clunky and forced than to just keep things together. And doesn't Hierarchy imply inheritance?

Also what is the order that events/code is called if the master page isn't actually inherited?
 
Old January 22nd, 2010, 04:10 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Your page *can* see the master, but you need to cast it to an appropriate type.
For example, add this to your master"

public string GetStuff()
{
return "Hello World";
}

Then in your Page, add the following in Markup View:

<%@ MasterType VirtualPath="~/MasterPage.master" %>

where the VirtualPath attribute points to your master page. This causes the Master property to be strongly typed for the class defined in the master page's code behind.

Then in Code Behind, you can do this:

Label1.Text = this.Master.GetStuff();

The best way to answer the question about event order is to try it out. Wire up event handlers and set break points (or write to a Label), as explained in Chapter 14.

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!
The Following User Says Thank You to Imar For This Useful Post:
Punikin (January 22nd, 2010)
 
Old January 22nd, 2010, 04:17 PM
Registered User
 
Join Date: Jan 2010
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks, That really helps, i've been struggling with this for a few years now, and finally have the opportunuty to "re-design" our site in 3.5 and was hoping there was a fix to that problem. :-)

And i will try your suggestion about the events.
 
Old January 22nd, 2010, 05:04 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Tou're welcome. Glad I could 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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Master Pages micptpuser ASP.NET 2.0 Basics 6 January 8th, 2009 04:50 AM
Master Pages Jayahar ASP.NET 3.5 Basics 1 September 2nd, 2008 04:20 PM
Master Pages, Content Pages and CSS carliviris Visual Studio 2005 0 January 8th, 2008 05:56 PM
cross-page posting within pages with master file.. poogles ASP.NET 2.0 Basics 2 August 6th, 2007 05:11 AM
Master Page/Content Pages coleenh ASP.NET 2.0 Basics 1 September 26th, 2006 02:17 PM





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