Global Stylesheet

  • Thread starter Thread starter Michael Rich
  • Start date Start date
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
 
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">
 
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
 
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.
 
Back
Top