Changing styles sheets on a per user basis

G

Guest

I'm trying to change styles sheets on a per user basis. I was able to do this on the client using DOM, but how can I do this using the code behind page in the Load Page sub? I have a place that I save the user's preference for style (whihc style sheet they prefer to use), but how do I dynamically load the style sheet from the server at page load time?
 
K

Ken Cox [Microsoft MVP]

Hi Terry,

Inside the <head> tag, add a link tag that is set to run as a server-side
control. Give it an ID but not an href:

<link id="stlysht" rel="styleSheet" runat="server"></link>

In your code behind, declare the control (using the ID) as a generic
control. (Normally, VS.NET does it for you.)

Protected stlysht As _
System.Web.UI.HtmlControls.HtmlGenericControl

In your page load, add an href attribute and the place it should find the
stylesheet:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' Get the cookie preference here
' Use Ifs or Case statements as required
If 1 = 1 Then
stlysht.Attributes.Add _
("href", _
"http://www.aspalliance.com/css/aspalliance.css")
End If
End Sub

Does this help?

Ken
MVP [ASP.NET]
 

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,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top