473,395 Members | 1,756 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,395 software developers and data experts.

Accessing a top-level master page from a web control

Hi guys

I'm trying to make my code as streamlined as possible, and add CSS file
references dynamically when they are required, for example, if a page
contains a webcontrol, then the related CSS file is added by the webcontrol.

This prevents me having to remember to add the CSS file to the page if I use
a certain webcontrol.

I have a MasterPage with an array of StyleSheets, and a public function for
adding new stylesheets. That works great from either a content page, or the
content page of a nested master.

However, how can I do it from webcontrol? The nesting is something like...

MyMaster.master - contains public AddStyleSheet() function
- AboutMySite.master
- About_Home.aspx
- MyWebControl.aspx - this needs to be able to add its stylesheet using
AddStyleSheet() from the top-level master.

Is what I'm trying to do possible, and if so how can I this?!

Thanks,
Dan
Sep 1 '08 #1
5 2692
Hi Dan,

Yes, it is possible. You master page has a type, depending on what name you
gave to it. I will assume that it is "MyMaster".

So, simply:

((MyMaster)Page.Master).AddStyleSheet(...);
--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

"musosdev" <mu*******@community.nospamwrote in message
news:D3**********************************@microsof t.com...
Hi guys

I'm trying to make my code as streamlined as possible, and add CSS file
references dynamically when they are required, for example, if a page
contains a webcontrol, then the related CSS file is added by the
webcontrol.

This prevents me having to remember to add the CSS file to the page if I
use
a certain webcontrol.

I have a MasterPage with an array of StyleSheets, and a public function
for
adding new stylesheets. That works great from either a content page, or
the
content page of a nested master.

However, how can I do it from webcontrol? The nesting is something like...

MyMaster.master - contains public AddStyleSheet() function
- AboutMySite.master
- About_Home.aspx
- MyWebControl.aspx - this needs to be able to add its stylesheet
using
AddStyleSheet() from the top-level master.

Is what I'm trying to do possible, and if so how can I this?!

Thanks,
Dan
Sep 1 '08 #2
That works, thanks!

"Coskun SUNALI [MVP]" wrote:
Hi Dan,

Yes, it is possible. You master page has a type, depending on what name you
gave to it. I will assume that it is "MyMaster".

So, simply:

((MyMaster)Page.Master).AddStyleSheet(...);
--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

"musosdev" <mu*******@community.nospamwrote in message
news:D3**********************************@microsof t.com...
Hi guys

I'm trying to make my code as streamlined as possible, and add CSS file
references dynamically when they are required, for example, if a page
contains a webcontrol, then the related CSS file is added by the
webcontrol.

This prevents me having to remember to add the CSS file to the page if I
use
a certain webcontrol.

I have a MasterPage with an array of StyleSheets, and a public function
for
adding new stylesheets. That works great from either a content page, or
the
content page of a nested master.

However, how can I do it from webcontrol? The nesting is something like...

MyMaster.master - contains public AddStyleSheet() function
- AboutMySite.master
- About_Home.aspx
- MyWebControl.aspx - this needs to be able to add its stylesheet
using
AddStyleSheet() from the top-level master.

Is what I'm trying to do possible, and if so how can I this?!

Thanks,
Dan

Sep 1 '08 #3
Hi again,

Although you're code is right, in my situation I'm getting an error....

Unable to cast object of type 'ASP._mp_about_master' to type 'musosmaster'.

This is coming from the following line of code on my web control...

((musosmaster)Page.Master).StyleSheets.Add(new
StyleSheet("widget_fromtheblog.css", "screen"));

....where the webcontrol is on master page (_mp_about), which is nested
inside another master page (musosmaster), which is where the
StyleSheets.Add() functionality is.

Can you explain how to modify the code so it's looking at the parent
masterpage, rather than the masterpage that holds the control!?

Thanks,
Dan


"Coskun SUNALI [MVP]" wrote:
Hi Dan,

Yes, it is possible. You master page has a type, depending on what name you
gave to it. I will assume that it is "MyMaster".

So, simply:

((MyMaster)Page.Master).AddStyleSheet(...);
--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

"musosdev" <mu*******@community.nospamwrote in message
news:D3**********************************@microsof t.com...
Hi guys

I'm trying to make my code as streamlined as possible, and add CSS file
references dynamically when they are required, for example, if a page
contains a webcontrol, then the related CSS file is added by the
webcontrol.

This prevents me having to remember to add the CSS file to the page if I
use
a certain webcontrol.

I have a MasterPage with an array of StyleSheets, and a public function
for
adding new stylesheets. That works great from either a content page, or
the
content page of a nested master.

However, how can I do it from webcontrol? The nesting is something like...

MyMaster.master - contains public AddStyleSheet() function
- AboutMySite.master
- About_Home.aspx
- MyWebControl.aspx - this needs to be able to add its stylesheet
using
AddStyleSheet() from the top-level master.

Is what I'm trying to do possible, and if so how can I this?!

Thanks,
Dan

Sep 1 '08 #4
Hi Dan,

"MasterPage" class has also a property called "Master". So, in your case,
you may use "Page.Master.Master".

Description of Master property within MasterPage class from MSDN: Gets the
parent master page of the current master in nested master pages scenarios.

--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

"musosdev" <mu*******@community.nospamwrote in message
news:D1**********************************@microsof t.com...
Hi again,

Although you're code is right, in my situation I'm getting an error....

Unable to cast object of type 'ASP._mp_about_master' to type
'musosmaster'.

This is coming from the following line of code on my web control...

((musosmaster)Page.Master).StyleSheets.Add(new
StyleSheet("widget_fromtheblog.css", "screen"));

...where the webcontrol is on master page (_mp_about), which is nested
inside another master page (musosmaster), which is where the
StyleSheets.Add() functionality is.

Can you explain how to modify the code so it's looking at the parent
masterpage, rather than the masterpage that holds the control!?

Thanks,
Dan


"Coskun SUNALI [MVP]" wrote:
>Hi Dan,

Yes, it is possible. You master page has a type, depending on what name
you
gave to it. I will assume that it is "MyMaster".

So, simply:

((MyMaster)Page.Master).AddStyleSheet(...);
--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

"musosdev" <mu*******@community.nospamwrote in message
news:D3**********************************@microso ft.com...
Hi guys

I'm trying to make my code as streamlined as possible, and add CSS file
references dynamically when they are required, for example, if a page
contains a webcontrol, then the related CSS file is added by the
webcontrol.

This prevents me having to remember to add the CSS file to the page if
I
use
a certain webcontrol.

I have a MasterPage with an array of StyleSheets, and a public function
for
adding new stylesheets. That works great from either a content page, or
the
content page of a nested master.

However, how can I do it from webcontrol? The nesting is something
like...

MyMaster.master - contains public AddStyleSheet() function
- AboutMySite.master
- About_Home.aspx
- MyWebControl.aspx - this needs to be able to add its stylesheet
using
AddStyleSheet() from the top-level master.

Is what I'm trying to do possible, and if so how can I this?!

Thanks,
Dan

Sep 1 '08 #5
Hi

That worked great, thank you! I now have a peice of code in each of the web
controls that can find the MasterPage and insert the stylesheet.

One thing I did notice, I tried to put a function in a static class to do
it, but it wouldn't let me, saying there was no "this" inside a static
function. Here's the code I was trying...

public static void InsertStyleSheet(StyleSheet css)
{
try { ((musosmaster)Page.Master).StyleSheets.Add(css); }
catch { ((musosmaster)Page.Master.Master).StyleSheets.Add( css); }
}

Can anyone point me in the direction how I might be able to get this
function working globally, rather than having to add it to each WebControls'
cs file?! I thought about putting it in my master page, but then I'd have the
same problem finding it from the webcontrol I think?!
Dan


"Coskun SUNALI [MVP]" wrote:
Hi Dan,

"MasterPage" class has also a property called "Master". So, in your case,
you may use "Page.Master.Master".

Description of Master property within MasterPage class from MSDN: Gets the
parent master page of the current master in nested master pages scenarios.

--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

"musosdev" <mu*******@community.nospamwrote in message
news:D1**********************************@microsof t.com...
Hi again,

Although you're code is right, in my situation I'm getting an error....

Unable to cast object of type 'ASP._mp_about_master' to type
'musosmaster'.

This is coming from the following line of code on my web control...

((musosmaster)Page.Master).StyleSheets.Add(new
StyleSheet("widget_fromtheblog.css", "screen"));

...where the webcontrol is on master page (_mp_about), which is nested
inside another master page (musosmaster), which is where the
StyleSheets.Add() functionality is.

Can you explain how to modify the code so it's looking at the parent
masterpage, rather than the masterpage that holds the control!?

Thanks,
Dan


"Coskun SUNALI [MVP]" wrote:
Hi Dan,

Yes, it is possible. You master page has a type, depending on what name
you
gave to it. I will assume that it is "MyMaster".

So, simply:

((MyMaster)Page.Master).AddStyleSheet(...);
--
All the best,
Coskun SUNALI
MVP ASP/ASP.NET
http://sunali.com
http://www.propeople.dk

"musosdev" <mu*******@community.nospamwrote in message
news:D3**********************************@microsof t.com...
Hi guys

I'm trying to make my code as streamlined as possible, and add CSS file
references dynamically when they are required, for example, if a page
contains a webcontrol, then the related CSS file is added by the
webcontrol.

This prevents me having to remember to add the CSS file to the page if
I
use
a certain webcontrol.

I have a MasterPage with an array of StyleSheets, and a public function
for
adding new stylesheets. That works great from either a content page, or
the
content page of a nested master.

However, how can I do it from webcontrol? The nesting is something
like...

MyMaster.master - contains public AddStyleSheet() function
- AboutMySite.master
- About_Home.aspx
- MyWebControl.aspx - this needs to be able to add its stylesheet
using
AddStyleSheet() from the top-level master.

Is what I'm trying to do possible, and if so how can I this?!

Thanks,
Dan

Sep 2 '08 #6

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

Similar topics

1
by: majk | last post by:
hey! Im looking for a db tutoral which covers accessing a Microsoft SQL database on windows. I will be using VC++ if it matters. NO details just a basic introduction! Oracle DB access using...
1
by: Gregor | last post by:
I'm having problems accessing a global array variable from within a function. I have something like this: ------------------------------------ var detail = new Array( 20 ); detail = "hello"; ...
1
by: P G | last post by:
Hi all, I am a newbie to javascript. Please help me with this.... I have problem accessing subelement tag content from parent tag in javascript. I would like to change the color of text from red...
3
by: gsb | last post by:
I'd like to get the offset coordinates, top & left, of an embedded Flash movie. <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ...
9
by: Swami | last post by:
I was wondering how I can programmatically find out the path of an installed program. I have an application that needs access to a config file that resides in the folder of another application. ...
1
by: jim | last post by:
Hi Ng I have got a hughes problem. I have got a file which I have been working on for quite a while. But now suddently no matter what button I am pressing there comes an error saying: Error...
5
by: Peter | last post by:
I have 3 ASP.NET forms written in C#, I also have 3 frames (left, top and bottom) one for each form. My question is if I have data on one form in the bottom frame how do I access this data when I...
9
by: Bob Day | last post by:
VS 2003, vb.net , sql msde... I have an application with multiple threads running. Its a telephony application where each thread represents a telephone line. For code that would be the same...
2
by: Arnaud Diederen | last post by:
Hi, Let's say I have a webapp 'root' window into which I include all my important JavaScript, including functions that I use as constructors. Let's say I have a 'class' whose constructor is...
1
by: deece | last post by:
HI There! I hope someone can help me with this as I have been searching for about 2 weeks now for an answer and I have to admit that I am a designer and not much of a coder so all help would be...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.