p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 (http://p2p.wrox.com/forumdisplay.php?f=389)
-   -   Base Page and Master Pages (http://p2p.wrox.com/showthread.php?t=73103)

Will March 10th, 2009 12:15 PM

Ok thanks.

Sorry about delayed reply currently decorating and haven't had access to the internet for a couple of days.

Punikin January 22nd, 2010 03:53 PM

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?

Imar January 22nd, 2010 04:10 PM

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.



Punikin January 22nd, 2010 04:17 PM

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.

Imar January 22nd, 2010 05:04 PM

Tou're welcome. Glad I could help...



All times are GMT -4. The time now is 09:57 PM.

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