More in this section

Forums / Developing with Sitefinity / Feature Request: Assign MasterPage using a MasterPage Object

Feature Request: Assign MasterPage using a MasterPage Object

3 posts, 0 answered
  1. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    22 Sep 2009
    Link to this post
    Here's a request that should be simple to fulfill on your end and would allow me to eliminate an ugly and cumbersome hack on my end.

    The PageBase object has a MasterPage property that accepts a path to the .master file. I would like to a way to provide a System.Web.UI.MasterPage object instead.

    Why? All of my server controls are in a separate class library. I can't access my custom MasterPage class from these controls because it exists only in the Sitefinity web site assemblies.

    I'd like to move my custom, MasterPage-derived class into the same assembly as my server controls. However, if I do that, there's no way to tell Sitefinity to associate that master page class with a Sitefinity page. This is because there's no physical path to the MasterPage, it is simply a class derived from System.Web.UI.MasterPage.

    A simple PageBase.SetMasterPage(System.Web.UI.MasterPage mp) method would solve the problem for me. I suspect PageBase.MasterPage already sets a System.Web.UI.MasterPage field internally.

    Thanks for your consideration. Let me know if you need any clarification or if you have a workaround to my issue.

    Jeff
  2. Jeff
    Jeff avatar
    124 posts
    Registered:
    05 Aug 2007
    22 Sep 2009
    Link to this post
    I came up with an acceptable workaround to this issue (though I'd still like to have the feature I described). Sometimes merely explaining your issue allows you to solve it yourself. :)

    What I've done is created a class derived from MasterPage in my class library. Let's call it MyMasterPage. It contains all the custom code I need in the MasterPage class.

    Then, in the Sitefinity project, I derive the MasterPage I'm using as a template from MyMasterPage. It is essentially markup with no significant code.

    Now my controls can access the important properties and methods from the MyMasterPage and I can still attach a MasterPage to a Sitefinity page. It works pretty well.
  3. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    24 Sep 2009
    Link to this post
    Hello Jeff,

    This sounds indeed as a pretty good workaround. The idea is also great. We will log it for implementing in Sitefinity 4.0.

    Greetings,
    Georgi
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
3 posts, 0 answered