This is a migrated thread and some comments may be shown as answers.

[Solved] StyleSheetRegistrar on partial view

3 Answers 168 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
nachid
Top achievements
Rank 1
nachid asked on 30 Mar 2010, 12:46 PM

Hi
I am trying to add a styleSheet to my partial view and there is no way to have it working.
On my partial view I have this

 <% Html.Telerik().StyleSheetRegistrar().StyleSheets(s =>s.AddGroup("form", g =>g.Add("form.css").Compress(true))); %>

On my master page, I have the usual call to Render() method

If I remove the call from the partial view and put it on the master page, it works fine

What am I doing wrong?
It looks like StyleSheetRegistrar is not working on partial views.
Why is this?

Thank you for your help
nachid

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 30 Mar 2010, 12:51 PM
Hello nachid,

Indeed the StyleSheetRegistrar does not work in partial views. The reason for this is very simple - the "master" StyleSheetRegistrar defined in the <head /> tag of your .master page has been already rendered when the partial view is processed. This means that the master StyleSheetRegistrar has already output its stylesheets before the "child" StyleSheetRegistrar (the one in the partial view) is processed. A possible workaround is to move the "master" StyleSheetRegistrar at the end of your .master page. However this would make your HTML invalid as stylesheet files must be registered within the <head /> tag.

Regards,
Atanas Korchev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
nachid
Top achievements
Rank 1
answered on 30 Mar 2010, 02:18 PM
Thanks Atanas  for your very quick answer
It is very clear for me now why I works the way it is.

It would be nice if it was possible to render the StyleRegistrar more than once
I could have rendered it my partial view and I my master page.

Regards
Nachid
0
Rick
Top achievements
Rank 1
answered on 14 Sep 2010, 10:21 PM
Although this won't work with a PartialView, you can leverage StyleSheetRegistrar on a View and your Master Page using ContentPlaceholder controls.

Take for example this code in your Master Page's <head> section:

<% Html.Telerik().StyleSheetRegistrar()
    .DefaultGroup(group => group.Add("telerik.common.css")
                .Add("telerik.default.css")
                .Add("telerik.common.override.css")
                .Add("Global.css")
%>
<asp:ContentPlaceHolder ID="AdditionalCss" runat="server" />
<% Html.Telerik().StyleSheetRegistrar().Render(); %>


The code adds the style sheets to the DefaultGroup of the StyleSheetRegistrar, but does not call the Render method.

After that initial block there is a ContentPlaceholder with ID "AdditionalCss".  Using this ContentPlaceholder in your View (.aspx file) will allow you to add additional stylesheets to the DefaultGroup--but again, you don't want to call Render.  That call remains in the Master Page and is invoked after all your content is assembled into one response stream.

Code in the View (.aspx file) would look like this:

<asp:Content ContentPlaceHolderID="AdditionalCss" runat="server">
    <% Html.Telerik().StyleSheetRegistrar()
        .DefaultGroup(group => group.Add("~/Content/MyPage.css"));
    %>
</asp:Content>

Having the code arranged in this order, allows you to leverage the features of the StyleSheetRegistrar like combining, and also control the cascade of style sheets (since their order in the final HTML source matters).

Tags
General Discussions
Asked by
nachid
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
nachid
Top achievements
Rank 1
Rick
Top achievements
Rank 1
Share this question
or