473,246 Members | 1,423 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,246 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 2436
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.