Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...Changing module.css dynamically on loginChanging module.css dynamically on login
Previous
 
Next
New Post
1/17/2013 10:59 AM
 

Hi all,

I am developing a custom module in DNN 6.  I would like to know how I can have two module css files and switch between them depending on the user logging in.

Example: User A logs in.  I set the module.css file to a blue style (module_blue.css).  User B logs in, I set the module.css file to a red style (module_red.css).

Further information: I have a custom field in the user-profile that determines which style should be used.  So after the user logs into the DNN site and navigates to the page with the custom module on it, the module will know which module.css to use.

How would I achieve this in code?

Thanks for any help!


 
New Post
1/18/2013 5:39 AM
 

I've managed to solve this by using the following code on View.ascx Page_Init()

'Change the stylesheet depending on a property setting of the user's profile

            Dim cssStyle As HtmlLink = New HtmlLink()
            cssStyle.Attributes.Add("rel", "stylesheet")
            cssStyle.Attributes.Add("type", "text/css")

            Select Case yourSetting
                Case UseRedCSS
                    cssStyle.Href = "/DesktopModules/yourModule/red.css"
                Case UseBlueCSS
                    cssStyle.Href = "/DesktopModules/yourModule/blue.css"
                Case Else
                    cssStyle.Href = "/DesktopModules/yourModule/green.css"
            End Select
            Page.Header.Controls.Add(cssStyle)


The only thing I would suggest improving is the path to the .css files.  I would prefer a relative path but I'm not sure what that looks like.  This gets loaded after the module.css so it will override any styles in the module.css file.

 
New Post
1/18/2013 10:09 AM
 
Another approach would be to have your custom module emit a wrapping div round all the content and give it a class name that is generated in the code.

This would:
- work in all your controls, not just the view.
- allow you to target the generated class in standard module/portal etc css files.

Best wishes,
- Richard
Agile Development Consultant, Practitioner, and Trainer
www.dynamisys.co.uk
 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Skins, Themes, ...Skins, Themes, ...Changing module.css dynamically on loginChanging module.css dynamically on login


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out