Changing styles sheets on a per user basis

Discussion in 'ASP .Net' started by =?Utf-8?B?VGVycnk=?=, Feb 4, 2004.

  1. 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?
     
    =?Utf-8?B?VGVycnk=?=, Feb 4, 2004
    #1
    1. Advertising

  2. 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]


    "Terry" <> wrote in message
    news:...
    > 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?
     
    Ken Cox [Microsoft MVP], Feb 4, 2004
    #2
    1. Advertising

  3. Works like a charm...Many Thanks...Terry
     
    =?Utf-8?B?VGVycnk=?=, Feb 4, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    481
  2. Noozer
    Replies:
    12
    Views:
    3,811
    dorayme
    Jan 19, 2005
  3. muriwai
    Replies:
    2
    Views:
    616
    muriwai
    May 23, 2007
  4. Replies:
    14
    Views:
    558
    bijeshn
    Apr 8, 2008
  5. Yaroslav Klyukin

    Java CPU utilization on a per-thread basis

    Yaroslav Klyukin, Dec 22, 2008, in forum: Java
    Replies:
    1
    Views:
    1,578
    Mark Space
    Dec 22, 2008
Loading...

Share This Page