473,387 Members | 1,621 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Nested Masterpages and naming

Hi,

I've been struggling with this one for a couple of hours without much
joy.

Basically, I've got a set of nested masterpages (3 as it happens). I'm
dynamically generating a new page in code and want to be able to
populate the ContentPlaceholders of the inner-most masterpage at
run-time.

So, assuming the masterpages are named Corporate.Master,
Division.Master, Dept.Master what I want to be able to do is
dynamically load some content into the placeholders of the Dept.Master.

Now, I have control over Dept.Master so I know what ID's I've given to
the placeholders on it. I don't, however, know what the placeholder
ID's are for the Division.Master and Dept.Master - at least not at
run-time. The actual html that i squirt into the placeholders on the
Dept.Master is held in SQL. Each piece of html has an ID associated
with it which is the content placeholder in which to be squirted...

The purpose of this is to allow the Corporate and Division masterpages
to be hacked around at someone else's discretion. And because i'm
dynamically creating the aspx pages I don't need to worry about that.

All I need to do is know how to get a reference to the content
placeholder of my Dept.Master from code...

Now, this is the bit that is stumping me. FindControl doesn't seem to
work on the nested masterpages. It appears that I have to call
FindControl on the outer-most masterpage (in this case
Corporate.Master) and use the qualified ID - something like
page.Master.Master.Master.FindControl("CorporateBo dyPh:DivisionBodyPh:DeptBodyPh").
All i store in SQL is the DeptBodyPh id and the actual html i want to
use.

Unfortunately, I can't see anyway of determing the nesting path of my
placeholders to be able to construct the ID correctly.

Can anyone shed any light? Apologies for this being a bit of a ramble.
That can be put down in part to the lateness of the hour, but mostly to
the pub i've just returned from...

Cheers
Ian

And for a final bit of ramble, a code snippet:

void BuildPage()
{
// Dynamically create a page
Page page = new Page();

// Associate it with a master page
page.MasterPageFile = "~/Dept.Master" // retrieved from SQL
page.AppRelativeVirtualPath = "~/";

// Get the placeholder content from SQL
Dictionary<string, string> placeholders = TalkToSQL();

// Populate placeholders
foreach (string placeholderId in placeholders.Keys)
{
// Get the content placeholder - the bit that is causing grief
ContentPlaceholder ph = page.Master.FindControl(placeholderId);

// Fill it with html
LiteralControl lit = new
LiteralControl(placeholders[placeholderId]);

// And add to the ph
ph.Controls.Add(lit);
}

// Should be done now
page.ProcessRequest();
}

Feb 8 '06 #1
2 2444
I had a similar problems with nested masterpages findcontrol due to the weird
naming that maserpages causes. Eventually was able to get at things using
findcontrol on the Form directly.

Form1.FindControl("controlname")

mike
"it********@gmail.com" wrote:
Hi,

I've been struggling with this one for a couple of hours without much
joy.

Basically, I've got a set of nested masterpages (3 as it happens). I'm
dynamically generating a new page in code and want to be able to
populate the ContentPlaceholders of the inner-most masterpage at
run-time.

So, assuming the masterpages are named Corporate.Master,
Division.Master, Dept.Master what I want to be able to do is
dynamically load some content into the placeholders of the Dept.Master.

Now, I have control over Dept.Master so I know what ID's I've given to
the placeholders on it. I don't, however, know what the placeholder
ID's are for the Division.Master and Dept.Master - at least not at
run-time. The actual html that i squirt into the placeholders on the
Dept.Master is held in SQL. Each piece of html has an ID associated
with it which is the content placeholder in which to be squirted...

The purpose of this is to allow the Corporate and Division masterpages
to be hacked around at someone else's discretion. And because i'm
dynamically creating the aspx pages I don't need to worry about that.

All I need to do is know how to get a reference to the content
placeholder of my Dept.Master from code...

Now, this is the bit that is stumping me. FindControl doesn't seem to
work on the nested masterpages. It appears that I have to call
FindControl on the outer-most masterpage (in this case
Corporate.Master) and use the qualified ID - something like
page.Master.Master.Master.FindControl("CorporateBo dyPh:DivisionBodyPh:DeptBodyPh").
All i store in SQL is the DeptBodyPh id and the actual html i want to
use.

Unfortunately, I can't see anyway of determing the nesting path of my
placeholders to be able to construct the ID correctly.

Can anyone shed any light? Apologies for this being a bit of a ramble.
That can be put down in part to the lateness of the hour, but mostly to
the pub i've just returned from...

Cheers
Ian

And for a final bit of ramble, a code snippet:

void BuildPage()
{
// Dynamically create a page
Page page = new Page();

// Associate it with a master page
page.MasterPageFile = "~/Dept.Master" // retrieved from SQL
page.AppRelativeVirtualPath = "~/";

// Get the placeholder content from SQL
Dictionary<string, string> placeholders = TalkToSQL();

// Populate placeholders
foreach (string placeholderId in placeholders.Keys)
{
// Get the content placeholder - the bit that is causing grief
ContentPlaceholder ph = page.Master.FindControl(placeholderId);

// Fill it with html
LiteralControl lit = new
LiteralControl(placeholders[placeholderId]);

// And add to the ph
ph.Controls.Add(lit);
}

// Should be done now
page.ProcessRequest();
}

Feb 8 '06 #2
Oh, that sounded so promising but, alas, it didn't work either. Not to
worry, I think I'm going to rejig the way I'm structuring my project so
it doesn't use a third-tier of masterpage, instead uses templated aspx
pages that can render the content through normal
System.Web.UI.Placeholder controls. Hopefully that will get me
further...

Feb 8 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote:...
4
by: Steve Franks | last post by:
I have this cool nested master page scenario working great. However what is the correct way to be able to access a strongly typed property at the top level master from a content page that has a...
0
by: Arthur Dent | last post by:
Anyone know if there is planned to be an update to VS2K5 to allow for editing nested master pages in ASP.NET in design view? This feature would be really useful for something i need, but the...
5
by: Nick Wouters | last post by:
Dear All In Classic ASP I used CSS for ALL layout. Now in ASP.NET version 2 I am testing out Masterpages as they come in very handy. It seems like it is replacing CSS for layout but what is...
4
by: rshillington | last post by:
Consider a site with 3 files the purpose of which I hope is evident in their names: SiteMaster.master, threeColumnMaster.Master, which uses SiteMaster.master as its master page and default.aspx...
2
by: delvsb | last post by:
Hi. I would like to ask whether it is normal that you cannot view the child master page in the design view when using nested masterpages. ex. i have the ff files maintemplate.master ...
6
by: =?Utf-8?B?U3RlcGhlbiBIYXRmaWVsZA==?= | last post by:
I have two masterpages in a web application. One is used for the login and logout pages. The other is used for all other pages in the application. The difference between the two masterpages is...
8
by: Sheldon | last post by:
Hi, Can anyone help with this problem with setting up nested structures and initializing them for use. I have created several structs and placed them in a super struct that I will then pass to...
8
by: phub11 | last post by:
Hi - I have a function which appends row(s) to the bottom of a table: function mouseUpHandler() { var table = document.getElementById("mytable"); var rowCount = table.rows.length; var...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.