Master pages, how to make them work?

R

Rob R. Ainscough

Again another simple concept that appears NOT to be intuitive or I'm just
stupid. I've read the WROX book and the example doesn't actually show how
the .master page links in the other content pages? Kinda sorta a critical
point no?

Am I missing something?

Rob.

P.S. the day I find a book that actually is useful rather than just a
checkmark next to "covered that topic" -- of course there is MSDN (what a
joke that is, worst documentation I've ever wittnessed -- samples?? no
links or lists of what parameters can be used, nothing. Sorry, just very
frustrated with complete lack of useful documentation that doesn't require
many hours playing the search and hunt game. If I documented my code as
poorly as MSDN documents VS 2005, I would be out of a job a long time ago.
 
B

Bruno Alexandre

Professional ASP.NET 2.0 from Wrox is my Bible :-D since ASP 3.0 I just love
their books ...

....but, back to your problem...

hopping that you have the same book, look at page 252 and you will see that
they have 2 files

MyMaster.master (the master page) and
Default.aspx (the default page)

in Listing 8.1: A sample Master Page (p.254)
you can see that ALL MASTER PAGES start with:

<%@ Master ...

and in the Listing 8.3: The content page that uses Wrox.Master (p.258)
you can see that ALL CONTENT PAGES have in the start line
<%@ ... MasterPageFile="Wrox.master" ...


even if you do not have the book, I think I made my point ;-)
 
B

Bruno Alexandre

I forgot to tell you...

in your Master.Page you need to have a minimum of ONE ContentPlaceHolder,
like

<asp:ContentPlaceHolder id="leftPane" runat="server" >
</asp:ContentPlaceHolder>

so, the Server could take the conten page and put the actual content in the
place holder


in your content pages you need to write the code inside a PlaceHolder
control, using the example above:

<asp:Content id="myLeftContent" ContentPlaceHolder="leftPane"
runat="server">

... your html / asp.net / javascript code :)

</asp:Content>
 
R

Rob R. Ainscough

Nope not getting it, yes I have the book.

In my Master.master I have an HTML table laided out with tranditional Header
(top), LeftSideBar (left), Primary Content (middle), Footer (bottom) in each
table cell has ContentPlaceHolder (IDs, cph_Header, cph_LeftSideBar,
cph_PrimaryContent, cph_Footer).

I've created a Header.aspx that links to the Master,

in Header.aspx --
....@ Page Language="VB" MasterPageFile="~/Master.master"
AutoEventWireup="false" CodeFile="Header.aspx.vb" Inherits="Header"
title="Header"...

....<asp:Content ID="c_Header" ContentPlaceHolderID="cph_Header"
Runat="Server">...

in Footer.aspx --
....@ Page Language="VB" MasterPageFile="~/Master.master"
AutoEventWireup="false" CodeFile="Footer.aspx.vb" Inherits="Footer"
title="Footer"...

....<asp:Content ID="c_Footer" ContentPlaceHolderID="cph_Footer"
Runat="Server">...

in LeftSideBar.aspx
....@ Page Language="VB" MasterPageFile="~/Master.master"
AutoEventWireup="false" CodeFile="LeftSideBar.aspx.vb"
Inherits="LeftSideBar" title="SideBar"...

....<asp:Content ID="c_LeftSideBar" ContentPlaceHolderID="cph_LeftSideBar"
Runat="Server">...

in PrimaryContent.aspx
....@ Page Language="VB" MasterPageFile="~/Master.master"
AutoEventWireup="false" CodeFile="PrimaryContent.aspx.vb"
Inherits="PrimaryContent" title="Content"...

....<asp:Content ID="c_PrimaryContent"
ContentPlaceHolderID="cph_PrimaryContent" Runat="Server">...

So what page do I reference if I'm testing from a Browser?? Do I need yet
another page?? This is where I'm confused. I can't reference Master.master
as that means nothing. What I would have expected VS 2005 to do (if I were
on the dev team that created VS) is automatically create a Master.aspx
(which is what I would reference from a Browser session) -- but VS 2005
doesn't do this so I'm stuck at this point?

Thanks, Rob.
 
V

Victoria Bolton

Master Pages don't work the same as a frameset.

I have 1 master page that has my header, footer and sidebar in it. This is
all part of the masterpage. I then have a single content holder that is the
are where all my pages will show up.

When I call one of those pages (for instance default.aspx which is my home
page) it displays showing the master page content as well.

If I'm reading your stuff write you are kind of defeating the object of
having a master page. If your header and footer etc are never going to
change throughout your site then put that info directly into the master
page.

Victoria
 
B

Bruno Alexandre

nahhhh...

there is no 4 content pages... just ONE content page with 4 asp:Content

------------------- master.page -----------------------------
<%@ master language="VB" %>

<script runat="server">
</script>

<html>
<head>
...
</head>
<body>

...
<asp:ContentPlaceHolder id="cph_Header" runat="server"
</asp:ContentPlaceHolder>
...
<asp:ContentPlaceHolder id="leftPane" runat="server"
</asp:ContentPlaceHolder>
...
<asp:ContentPlaceHolder id="cph_LeftSideBar" runat="server"
</asp:ContentPlaceHolder>
...
<asp:ContentPlaceHolder id="cph_Footer" runat="server"
</asp:ContentPlaceHolder>


</body>
</html>

------------------- default.aspx -----------------------------
<%@ Page Language="VB" MasterPageFile="~/Master.master"
AutoEventWireup="false" CodeFile="Header.aspx.vb" Inherits="Header"
title="Header"%>

<script runat="server">
</script>

<asp:Content ID="c_Header" ContentPlaceHolderID="cph_Header" Runat="Server">
... the content to add the header will be here
</asp:Content>

<asp:Content ID="c_PrimaryContent" ContentPlaceHolderID="cph_PrimaryContent"
Runat="Server">
... the content to add the Primary Content will be here
</asp:Content>

<asp:Content ID="c_LeftSideBar" ContentPlaceHolderID="cph_LeftSideBar"
Runat="Server">
... the content to add the Left Side Bar will be here
</asp:Content>

<asp:Content ID="c_Footer" ContentPlaceHolderID="cph_Footer" Runat="Server">
... the content to add the Footer will be here
</asp:Content>
 
G

Guest

So, how do you control the flow of each content controls and their contents?

You have absolutely defeated the purpose of the master page. Instead of
content holders for each section of your page's layout, instead take the
content that you would have inside of each of those content holders and put
them directly in your master page.
 
B

Bruno Alexandre

dam dude!!!

do you work with CorelDRAW?? it uses Master Pages in Object Manager

ONE DESIGN = Multiple pages

the propose of master pages is to have one page with the design, and the
rest is only content!, for example Microsoft website: the design is the same
for every page!!! what does it chage? left side options (is a menu with
diferent options and links on every page) so = contentplaceholder with a
menuView and you load diferent sources in every page

do you understand now?


Design is something diferent from coding... so master.pages give us the
possibility to have someone do the design, add a contentplaceholder in the
sopt and the coder do his thing to that spot...
 
R

Rob R. Ainscough

Ok, so I've put my header/footer code on my Master page and now have a
single main.aspx page. But, I'm still confused on how to get my other pages
i.e. Login.aspx, AcctMgmt.aspx, CustInfo.aspx etc. to be displayed in the
ContentPlaceHolder (cph_PrimaryContent) on my Master page?

I'm assuming, I will need to create a login.aspx as a content page and point
it to my master.page? But how do I dynamically change what page is
displayed in my ContentPlaceHolder (cph_PrimaryContent) ? i.e. user clicks
on a button in my sidebar which then need to load a page into my
PrimaryContent area (on my master page)? all done via code behind?
 
R

Rob R. Ainscough

So if I understand you correctly, I would have to duplicate the 4 "Content"
controls for EVERY single page that I want to display -- isn't this
defeating the purpose? How is this a benefit? Maybe if I'm doing VERY
simple stuff this could be a benefit, but as it stands right now it seems to
me framesets ARE MUCH more powerful and flexible.

I guess I'm missing something obvious?

I still don't see how a Master page can dynamically using different content
pages via code behind processing?

I thought the purpose of Master pages is to allow code behind references to
ContentPlaceHolders to set and/or obtain values in the reference pages? I
guess I don't see what benefit Master pages are doing for me?

Rob.
 
B

Bruno Alexandre

ok... NOW I KNOW what confundes you...

MASTER PAGES is not FRAMESET!!!!

you do not click on a button and change only ONE part of the page!
you click on a button (or link) and you navigate to a new page

Download the code for Chapter 8 of the ASP.NET 2.0 Worx book and execute the
examples in your Developer program (Web Developer Express or Visual Studio
2005)


as I told you once... if you a have a footer that is qual to several pages,
you use master page, if you have a diferent design for all the pages you DO
NOT USE master pages

for example one of my websites www.filterqueen.dk I use one Master.Page with
all the design, above menu links, and left treeview, and ONE content place
holder for the inside of the interior palebrown pane....

can you understand??? if completly diferent from framesets, framesets are
diferent things, and you're free to use it asp.net 2.0, but none real
developer recomend it.
 
R

Rob R. Ainscough

Exactly (I think) -- my thoughts exactly, seems to me there is no real
purpose to the Master page -- how can dynamic content be replaced in the
master page -- it can't from what I'm seeing? Can it? If so, someone
please show me how.

Seems to me, Master pages are VERY premitive templates that are not dynamic
at all. Can they do what framesets can do?

Rob.
 
R

Rob R. Ainscough

Ok, so after reading the pdf link, pg 76 clearly says "binding between
master and content pages is defined statically and cannot be changed or set
programmatically". So this means to me:

1. No easy way to migrate a frameset based web application -- in fact
migration is definitely NOT a good option
2. Every "content" page must be derived from the Master (or nested master)

No offense, but I'm going back to framesets as this "solution" is clearly
NOT going to make my life easier, in fact it will generate a ton of
migration work -- once again Microsoft missed the boat completely.

Don't know if I should laugh or cry.
 
B

Bruno Alexandre

framesets are the worst thing to do under web development...

in my website that I point to you, I have a tree menu in the left side and
that's in master.page, cause it's the same to all pages, even if I wanted
the menu to show other color when the user is in a menu page...

I'm only use ONE control for that!

by the way...

Master Pages DID NOT BEEN INVENTED to prevent developers using frames...

as I told you MASTER PAGES is not the same as FRAMESET's it's more like the
include files that we use to have in Classic ASP!
 
R

Rob R. Ainscough

Bruno,

yeah, I finally got that now -- I've got it working and the big saving grace
is the Master. functionality that can be used in code behind for any content
page. I think documentation was severely lacking in just about every place
I looked and my WROX books just restated what MSDN states. I think the key
that was missed is that Master pages ARE templates, sure they have a tad
more functionality, but if more time were spent saying they are "templates"
then that would have triggered the concept much more clearly. It's like
they didn't want to use the word "template" because master pages offer a
little more than that.

I think it would also have been beneficial if the rendering process were
presented more clearly also -- content pages are NOT true web pages even
though they have the aspx extension -- this again was completely NOT
presented. Since the end result is something very similar to framesets, it
would also have been more informative if that point of view were used to
help the learning transition over to Master page concept -- saying "it is
very different" doesn't really help.

But as far as converting existing web applications -- I'm still debating
whether it is worth the effort. And I'm still not sure how to get Forms
authentication to work with this approach?? Not to mention how to get SSL
to work correctly for parts of my site rather than the entire site.

Rob.
 
B

Bruno Alexandre

Hi Rob...

finally you got it :)

about the conversion, well... you knwo that you can have a master page that
is a content page also :)

page A = Master Page
page B = Content of A and Master Page A = result A + B
page C = Content of Master Page B = result A + B + C
page D = Content of Master Page A = result A + D

so, you can have a lot of master pages, 4 example:

1 for users, 1 for admins, 1 for secure website, etc...

as long as SSL, I worked with that and the only thing that I saw that was
diferent was the http changed to https, the rest is the same, developing for
http it's the same for https, only in https you knwo that all data is
encrypted in the client machine and decrypted where your server is...
 
O

offwhite

Rob,

It appears what you want to make ASP.NET 2.0 do is not how it actually
works. I like to read those books but I also find some video and
screencasts to be really helpful. I have a subscription here...

http://www.learnvisualstudio.net/

It is nice being able to watch a video which actually shows you how it
works. You can also get free video here...

http://www.dnrtv.com/

Once you have a better understanding of Master Pages you may want to
get into Atlas as the new UpdatePanel. That is the new approach to
what you appear to want to do with Framesets.

Also, you can dynamically change the value for the Master Page but you
have to do it in the PreInit handler. I have used that feature quite a
bit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,600
Members
45,179
Latest member
pkhumanis73
Top