Found one possible solution. Made a user control in my masterpage and put the user control in the header part of the master page. The user control outputs the <style css... > tag.
In my "go to room" click event the user control is loaded with the FindControl method, and updated with room.StyleSheet.Url property. Seems to work for now.
Hi,
If you are using EPiServer CMS you can call the RegisterCssFile(string path) method of your page to register the css in the header. If not, the code to achieve this looks something like this:
public bool RegisterCssFile(string path)
{
if (Header == null)
{
return false;
}
if (_registeredCssScripts[path] != null)
{
return true;
}
HtmlGenericControl link = new HtmlGenericControl("link");
link.Attributes["rel"] = "stylesheet";
link.Attributes["type"] = "text/css";
link.Attributes["href"] = ResolveUrl(path);
Header.Controls.Add(link);
_registeredCssScripts[path] = "true";
return true;
}
Hi!
This method did the trick, or sort of :)
Solution: Added a user control in the <header> of my masterpage. Added a method in the masterpage.cs file:
public void RegisterCssFile(string cssFilePath) { if (ucHeader != null) { ucHeader.AlternateStyleSheetURL = cssFilePath; } }
In the Header.ascx file we did this:
public partial class Header : System.Web.UI.UserControl { private string _alternateStylesheetUrl; protected void Page_Load(object sender, EventArgs e) { HtmlGenericControl _link = new HtmlGenericControl("link"); _link.Attributes.Add("rel", "stylesheet"); _link.Attributes.Add("type", "text/css"); _link.Attributes.Add("href", ResolveUrl("~/Layout/css/Kreftforeningen.css")); this.Controls.Add(_link); } protected void Page_PreRender(object sender, EventArgs e) { if (!String.IsNullOrEmpty(AlternateStyleSheetURL)) { HtmlGenericControl _linkAlt = new HtmlGenericControl("link"); _linkAlt.Attributes.Add("rel", "stylesheet"); _linkAlt.Attributes.Add("type", "text/css"); _linkAlt.Attributes.Add("href", AlternateStyleSheetURL); this.Controls.Add(_linkAlt); } } public string AlternateStyleSheetURL { get { return _alternateStylesheetUrl; } set { _alternateStylesheetUrl = value; } } }
The header is now set to be altered. In my Forum.ascx control, when displaying a Room or a list of Reply's we call a method:
private void ApplyStyleSheet(){// Set stylesheetRoomBase room = ForumHandler.GetRoom(RoomID);if (!string.IsNullOrEmpty(room.StyleSheet.Url)){MySolutionMaster master = Page.Master as MySolutionMaster;if (master != null){master.RegisterCssFile(ResolveUrl(room.StyleSheet.Url));}}}
Where RoomID is a plublic proptert set when loading a room.
Hope this helps someone else :)
Has anyone worked with the Stylesheet property in the Forum module?
I need to assign different stylesheets to different forums, but the documentation gives noe examples so I'm a bit lost. Do I need to make some sort of assignment in my Mastepage or can I set the stylesheet url in my panel and somehow reload my page? Are there any example code on how to do this?