Master Pages - CSS

J

Just Me

When using master pages, how can I get an external style sheet applied to
the specific page and still see the effects at design time. I want to have a
generic style sheet and specific ones for each page.

The only way I can think to do this is to put a link tag in the master with
a specific ID but leave the source blank. When the page loads it gets the
tag from the master and then adds the src attribute, the problem is that you
cannot see the effects of the style changes at design time.

Can someon offer a solution,
 
S

Stefan Kalcher

Just said:
When using master pages, how can I get an external style sheet applied to
the specific page and still see the effects at design time. I want to have a
generic style sheet and specific ones for each page.

The only way I can think to do this is to put a link tag in the master with
a specific ID but leave the source blank. When the page loads it gets the
tag from the master and then adds the src attribute, the problem is that you
cannot see the effects of the style changes at design time.

Can someon offer a solution,

<code>
Dim cssLink As New HtmlLink()
cssLink.Href = "~/styles.css"
cssLink.Attributes.Add("rel", "stylesheet")
cssLink.Attributes.Add("type", "text/css")
Header.Controls.Add(cssLink)
</code>

greets,
Stefan
 
S

Stefan Kalcher

The head tag in the master page must include runat="server" for the
Header property to work.

Just said:
Im afraid I cannot get this to work, it says it cannot be done in content
pages

greets,
Stefan
 
S

Stefan Kalcher

If you don't want the head-tag to be that ugly formatted in the
resulting html-code like it is with runat="server" attached, you could
use <asp:literal/> and access its Text-property via a public property in
the Master-Page.

Could look something like this:

Code:
Public Property adiCSS as string
	Get
		Return litAditionalStylesheet.Text
	End Get
	Set
		litAditionalStylesheet.Text = Value
	End Set
End Property

And the Client-Page:

Code:
Master.adiCSS = "<link href=""/images/add.css"" title=""whatever""" & _
	"rel=""stylesheet"" type=""text/css"" media=""screen""/>"

Just said:
Im afraid I cannot get this to work, it says it cannot be done in content
pages

greets,
Stefan
 
J

Just Me

I found Aanother way. If you create a themes directory, you can add the
style sheets in there and then add them into the page directive.

Thanks for your help

Stefan Kalcher said:
If you don't want the head-tag to be that ugly formatted in the
resulting html-code like it is with runat="server" attached, you could
use <asp:literal/> and access its Text-property via a public property in
the Master-Page.

Could look something like this:

Code:
Public Property adiCSS as string
Get
Return litAditionalStylesheet.Text
End Get
Set
litAditionalStylesheet.Text = Value
End Set
End Property

And the Client-Page:

Code:
Master.adiCSS = "<link href=""/images/add.css"" title=""whatever""" & _
"rel=""stylesheet"" type=""text/css"" media=""screen""/>"

Just said:
Im afraid I cannot get this to work, it says it cannot be done in content
pages

greets,
Stefan
 
C

clintonG

None of the suggestions actually answered how to support a different linked
stylesheet for each page that is supposed to be loaded. I'll touch on that
briefly noting there's many methodologies to generate stylesheet
declarations when the compiler is building the page.

Using Themes for example has also turned out to be quite complex and
convoluted with regard to the use of .css files. Make sure the difference
between a Theme and a StyleSheetTheme is well understood.

And... when using MasterPages with one or more Themes or StyleSheetThemes we
are compelled to use a base class that all pages inherit from. This enables
the Page_PreInit in the base class to be used to enable code to be used to
determine which page is being loaded so a certain Theme or stylesheet can
also be loaded. The .master does not support the Page_PreInit event.

K. Scott Allen's work explaining must be consulted [1]. Google's site:
filter is best used to find specific documentation at msdn2 where the latest
documentation is found.

// example
master pages overview site:msdn2.microsoft.com


<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/
MAP http://wikimapia.org/#y=43038073&x=-88043838&z=17&l=0&m=h

[1] http://odetocode.com/




Just Me said:
I found Aanother way. If you create a themes directory, you can add the
style sheets in there and then add them into the page directive.

Thanks for your help

Stefan Kalcher said:
If you don't want the head-tag to be that ugly formatted in the
resulting html-code like it is with runat="server" attached, you could
use <asp:literal/> and access its Text-property via a public property in
the Master-Page.

Could look something like this:

Code:
Public Property adiCSS as string
Get
Return litAditionalStylesheet.Text
End Get
Set
litAditionalStylesheet.Text = Value
End Set
End Property

And the Client-Page:

Code:
Master.adiCSS = "<link href=""/images/add.css"" title=""whatever""" & _
"rel=""stylesheet"" type=""text/css"" media=""screen""/>"

Just said:
Im afraid I cannot get this to work, it says it cannot be done in
content
pages

greets,
Stefan
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top