Global Stylesheet

M

Michael Rich

Is there a way to apply a single stylesheet to all pages in a VS.net ASP.net
project (vb)?

Thanks;
MR
 
B

bijoy

Yes. Save it on your webserver and link to it from all your pages.

For eg. <LINK href="mystylesheet.css" type="text/css" rel="stylesheet">
 
M

Matt Berther

Hello Michael,

Well, in all but the most trivial cases, you will likely have a base class
that all of your pages derive from. Add some code to register

<link href="mystylesheet.css" type="text/css" rel="stylesheet">

and it will be applied to any page you derive from. You might want to look
at Page.RegisterClientScriptBlock [1] for this. The name implies that it
should be only used with <script> tags, but this will work with any tag that
needs to insure that there is only one instance of the tag on the page.

This is typically much easier than adding the declaration to each page.

[1] http://msdn.microsoft.com/library/d...uipageclassregisterclientscriptblocktopic.asp
 
A

Aquila Deus

Matt said:
Hello Michael,

Well, in all but the most trivial cases, you will likely have a base class
that all of your pages derive from. Add some code to register

<link href="mystylesheet.css" type="text/css" rel="stylesheet">

and it will be applied to any page you derive from. You might want to look
at Page.RegisterClientScriptBlock [1] for this. The name implies that it
should be only used with <script> tags, but this will work with any tag that
needs to insure that there is only one instance of the tag on the page.

This is typically much easier than adding the declaration to each page.

[1]
http://msdn.microsoft.com/library/d...uipageclassregisterclientscriptblocktopic.asp

In 2.0 there will be Master Page, which acts as a template for all
pages, and allows you to put common UI part there.

In v1, however, you can code the template by yourself, see
http://msdn.microsoft.com/library/d...de/html/cpconcreatingtemplatedusercontrol.asp

The key is to bind all controls in template to their page classes using
reflection, because controls created in templates are not assigned
automatically to their corresponding fields in the page class. This
requires a lot of changes though.
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top