1

Which is best practice to achieve change in look (color of top bar) based on a custom user profile property?

Property has value yes/no/null.

  1. Using pre init event to change masterpage dynamically? I am worried this technique will update show last updated master page if property is null.

  2. Loading the css file dynamically via user control.

  3. Any other method?

7
  • If it's only about changing the top suite bar color and assuming you're using on-prem, I would suggest using a Delegate Control and load it into AdditionalPageHead.
    – Aveenav
    Commented Mar 21, 2014 at 16:45
  • I was planning to use user control and apply the change theme based on property
    – variable
    Commented Mar 21, 2014 at 16:53
  • If that's the case, the last logged in user will be overriding the theme. On each page refresh, theme will get updated.
    – Aveenav
    Commented Mar 21, 2014 at 17:34
  • Yes so current user will always get to see his theme because thats coded to check via user control in masterpage...
    – variable
    Commented Mar 21, 2014 at 17:35
  • You'd be constantly updating the web w/ theme for every refresh for every user that falls within those N groups
    – Aveenav
    Commented Mar 21, 2014 at 17:44

1 Answer 1

0

You have below options:

  • OPTION 1:

Use a custom user control where you get the UPS property & based on the value register a script using

ScriptManager.RegisterStartUp

or some other way based on whether you are using Update panels in your control.

Basically you have to do below in the script file/function: using JQuery get the top bar HTML element & set the css using

$(".classNameofTopBar").css({background-color: Red});

Alternatively you can add a CSS reference from your code https://stackoverflow.com/questions/2943037/adding-stylesheets-programmatically-in-asp-net

You must finally ensure that you have CACHING enabled for your user control as it will fire every time. You need to consider performance too and I believe the UPS property wont change that frequently.

  • OPTION 2:

See whether the UPS property is exposed to the OOB SharePoint property loader control. In SP 2010 we can just add a reference to OOB user control & then use it in your JS code to set the color as stated above.

http://chrisstahl.wordpress.com/2012/12/21/user-information-in-sharepoint-2010-with-help-of-the-spcwc-control/

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.