Help with ASPX Style Sheet

W

Wade Beasley

I have a web site I am working on for a client using ASP.NET with VB.Net
for the language. The client decided they needed the ability to choose
between different page layouts based on a setting in the database. I
have the header and footer working correctly by using a custom base page
and before the Page_Load loading the correct version from a subdirectory
with the Layout Number as the directory name. Now what I need is the
ability to have a similar style sheet in each of the numbered
subdirectories called template.css. Currently all the code for the
screens reside at the root level and the aspx pages point to a root
level "styles.css". What is the best way to accomplish this
redirecting to the correct subdirectory template.css file? Is it in
the base page too? If so how do I replace the currently specified
"styles.css" at runtime?

Thanks,
Wade
 
D

Davide Vernole [MVP]

Wade Beasley said:
I have a web site I am working on for a client using ASP.NET with
VB.Net for the language. The client decided they needed the ability
to choose between different page layouts based on a setting in the
database. I have the header and footer working correctly by using a
custom base page and before the Page_Load loading the correct version
from a subdirectory with the Layout Number as the directory name.
Now what I need is the ability to have a similar style sheet in each
of the numbered subdirectories called template.css. Currently all
the code for the screens reside at the root level and the aspx pages
point to a root level "styles.css". What is the best way to
accomplish this redirecting to the correct subdirectory template.css
file? Is it in the base page too? If so how do I replace the
currently specified "styles.css" at runtime?


Try this:

1) Insert inside the HEAD tag the following tag:
<LINK id="lnkStyles" rel="stylesheet" type="text/css" runat="server" />
2) Insert in the method delegate for the PageInit event this code:
this.lnkStyles.Attributes["href"] = yourFullPathOfCssFile;

where yourFullPathOfCssFile is the relative path, with the file name
included, of your css file.

HTH
 
M

Mr. Dot Net

If I understand you correctly then one method you could use is
HtmlGenericControl.

The code looks something like that in ASPX:

<LINK href="stylesheet1.css" type="text/css" runat="server" id="MyCssLink"
/>

Code-Behind:

protected HtmlGenericControl MyCssLink;

MyCssLink.Attributes["href"]=SomeOtherCssFile....
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top