This is a migrated thread and some comments may be shown as answers.
StyleSheetRegistrar
7 Answers 383 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Karl
Top achievements
Rank 1
Karl asked on 25 Nov 2009, 11:58 AM
Hello,

We are already using the Telerik ScriptRegistrar in our MVC website, and now wish to use the StyleSheetRegistrar 

The ScriptRegistrar allows to to add scripts to the bottom of the HTML from any page/usercontrol. Can we use StyleSheetRegistrar to add css files to the Head from any page/usercontrol? We can't get it to work this way. For example:

1) Add site wide stylesheet to Default.Master
<head runat="server">  
...  
<%Html.Telerik().StyleSheetRegistrar()  
.DefaultGroup(group => group.Add("~/Content/css/Site.css")).Render();%> 
....  
</head>   
 

 

 

this outputs correctly:

 

<head> 
....   
<link type="text/css" href="/Content/css/Site.css" rel="stylesheet"/>  
....  
</head> 

 

 

 


2) Add a stylesheet to a specific page:

 

<%   
Html.Telerik().StyleSheetRegistrar().StyleSheets(css => css.Add("~/Content/css/Page.css"));   
%> 
 


but the new stylesheet never outputs in the HTML:

 

<head> 
....   
<link type="text/css" href="/Content/css/Site.css" rel="stylesheet"/>  
....  
</head> 


Can the StyleSheetRegistrar work like this?

Thanks
Karl

 

 

 

7 Answers, 1 is accepted

Sort by
0
Karl
Top achievements
Rank 1
answered on 25 Nov 2009, 12:21 PM
Just to update this. If I move the StyleSheetRegistrar ... Render() to the bottom of the masterpage it works as expected, so it looks to be something to do with the ordering of events....
0
Georgi Krustev
Telerik team
answered on 25 Nov 2009, 03:30 PM
Hello Karl,

This is expected behavior.
Only the last StyleSheetRegistrar should have render() method. As a part of the normal ASP.NET lifecycle master page content is rendered first. Hence the group added in the viewpage will not be rendered.

All the best,
Georgi Krustev
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.
0
Karl
Top achievements
Rank 1
answered on 25 Nov 2009, 05:19 PM
Hi Georgi ,

Is it possible to output all of my css includes in the <head> of the document, and still be able to add css includes from my viewpages/usercontrols.

Could you explain?
0
Karl
Top achievements
Rank 1
answered on 27 Nov 2009, 10:36 AM
Approach I took was to add render method to head of master page, with content placeholder above:
    <asp:ContentPlaceHolder ID="HeadContent" runat="server"/>  
    <%   
        Html.Telerik().StyleSheetRegistrar()  
                .DefaultGroup(group => group.Add("~/Content/css/Site.css")).Render(); %>   

and in the view, added page specific css into HeadContent place holder:

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

Does anyone know a way that I can include css files in MVC usercontrols and for them to still output in the head of the HTML?
0
Georgi Krustev
Telerik team
answered on 30 Nov 2009, 02:39 PM
Hi Karl,

The posted code snippet in your last message clearly explains how to specify different styles and render them in the head of the page. Unfortunately the MS Ajax which loads the user controls does not evaluates JavaScript and CSS styles. Hence you cannot add CSS style from User control.

Kind regards,
Georgi Krustev
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.
0
cheburek
Top achievements
Rank 1
answered on 20 Jan 2010, 08:09 PM
Karl, thank you for your question - I'm currently the same solution as you with ContentPlaceHolder and also interested in registering CSS files from user controls. I think that it is possible to implement in such way:
1. Call Render method on the bottom of the page
2. get rendered part of page
3. find <head> 
4. insert required <link...> before </head>

But this is not a quick, quite complex and buggy solution
0
Karl
Top achievements
Rank 1
answered on 21 Jan 2010, 02:41 PM
Thanks for the suggestion. I'm adding sytlesheets in my view pages at the moment and it's working out ok but if I really need to add from the user controls I'll use your suggestion.
Tags
General Discussions
Asked by
Karl
Top achievements
Rank 1
Answers by
Karl
Top achievements
Rank 1
Georgi Krustev
Telerik team
cheburek
Top achievements
Rank 1
Share this question
or