
Just wondering how I can define various Script/Style Sheet groups, without having it included in the scripts that are rendered out... This way, I choose which groups I want to use given the current context.
Playing around with the samples, it seems like I can not define a group without it being included in the rendered scripts.
In the doco, it talks about having the following groups - jQueryBase, ListView, Form, ListLocal, ViewLocal, EditLocal - But how do you actually define and use these groups in a reusable fashion? I would expect that I would only have to define the group once and then just say I want to use that group within different pages or controls.
In Kaz original blog posts you could define these groups in the web config and then reference those groups for rendering in your page.
Also just a little bit of feedback, the URL's that are rendered are pretty hard core. Is there anyway of simplifying the URL. I know it needs to have a little bit of generated stuff for the versioning and caching, but couldn't it be something more like - /asset.axd?name=GroupName_js&id=fafafafasf - where id is the only what is needed for the versioning and caching.
Keep up the good work
Anthony
20 Answers, 1 is accepted
We have implemented support for defining asset groups from web.config. Unfortunately we didn't have the time to document it properly. It also supports specifying user defined id for the asset url (we couldn't do much work to automatically make it shorter as the url contains all files that are in the group). I am hereby sending you a sample code showing how to use assets defined in web.config. Check the web.config and the Index.aspx for details of the implementation.
I hope this helps,
Atanas Korchev
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.

Looks great... I'm just in the process of testing it out and rolling it through our code base.
One thing could you add a "debug" option to the add function... See below...
<telerik>
<webAssets>
<scripts>
<add name="gridAssetGroup" combined="true" debugcombined="false" enabled="true">
<items>
<add source="telerik.common.min.js" debug="telerik.common.js" />
<add source="telerik.grid.min.js" debug="telerik.grid.js"/>
<add source="telerik.grid.filtering.min.js"/>
</items>
</add>
</scripts>
</webAssets>
</telerik>
Note if you didn't fill in the debug option then the debug value would default to the source value. I have also added debugcombined option.
Also, one option I would like to see is a minify option. This could work by doing the following:
<add name="gridAssetGroup" combined="true" minify="true" debugminify="false" enabled="true">
<items>
<add source="telerik.common.min.js" debug="telerik.common.js" allowminify="false"/>
<add source="telerik.grid.min.js" debug="telerik.grid.js" allowminify="false"/>
<add source="telerik.grid.filtering.js"/>
</items>
</add>
By default allowminify is true.
Cheers and let me know what you think of the additions and whether they can make in into v1.
Anthony

One thing that I have found a little frustrating is that I would like more options besides just OnDocumentReady and OnWindowUnload, for instance I need to be able to declare global vars before any of the script files are rendered...
<script type="text/javascript"> |
//<![CDATA[ |
... |
//Global var's that I need setup before the script references are rendered |
... |
//]]> |
</script> |
<script type="text/javascript" src="/asset.axd?id=General"></script> |
<script type="text/javascript"> |
//<![CDATA[ |
jQuery(document).ready(function(){ |
... |
//Snippets reistered using OnDocumentReady |
}); |
... |
//]]> |
</script> |
Cheers
Anthony

In that I have the following in my master page...
<%= Html.Telerik().ScriptRegistrar()
.Scripts(scripts => scripts.AddSharedGroup("General"))%>
Then I have this in one of my pages that uses that above master page...
<% Html.Telerik().ScriptRegistrar()
.Scripts(scripts => scripts.AddSharedGroup("General")
.AddSharedGroup("Ajax")
.AddSharedGroup("Timeline")); %>
Now the telerik code throws the following exception when the master page runs AddSharedGroup("General"):
Local group with name "General" already exists.
at Telerik.Web.Mvc.UI.WebAssetItemCollectionBuilder.AddSharedGroup(String name)
at ASP.views_shared_site_master.<__Render__control1>b__2(WebAssetItemCollectionBuilder scripts) in h:\Code\PPS\Interface\PPS.Interface.PPSI\Views\Shared\Site.Master:line 86
at Telerik.Web.Mvc.UI.ScriptRegistrarBuilder.Scripts(Action`1 configureAction)
at ASP.views_shared_site_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in h:\Code\PPS\Interface\PPS.Interface.PPSI\Views\Shared\Site.Master:line 85
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Control.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children)
at System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
at System.Web.UI.Page.Render(HtmlTextWriter writer)
at System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer)
at System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter)
at System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Now the reason why I have general twice is that when I left it out, General was rendering after Ajax and Timeline... And General needs to run first. Hence I thought I would put it in the page and try and influence the order...
Now two things, firstly I wouldn't expect the system having a problem with trying to add the same group twice - what if I two different controls that can be used separately or together. To make sure they can run independently I would need to reference the required groups in both places. With the current implementation, there is no way I could make it work. In fact I know that this will become a problem with my date control. In the date control I will be adding the Date group and it's possible for the control to be used multiple times on the one page and as it currently stands I would have some problems. This is BIG problem for me when it comes to using the control at the current time... If a fix is a while off I may have to fix patch the source code till a new drop is given - which I would prefer not to have to do.
Secondly, maybe some thought needs to be given about how to sort out the ordering issue in general. I think I can get around this for the moment, but it could become a problem in other situations.
Cheers
Anthony

<script type="text/javascript" src="/asset.axd?id=kwAAAB-LCAAAAAAABADtvQdgHEmWJSYvbcp7f0r1StfgdKEIgGATJNiQQBDswYjN5pLsHWlHIymrKoHKZVZlXWYWQMztnbz33nvvvffee--997o7nU4n99__P1xmZAFs9s5K2smeIYCqyB8_fnwfPyJ-8UfT9qNHH2WrVVlMs7aolnffbf90dpk107pYtR-NPrqkr_d2dh6O7413d3fujXfos-lHj9p6ndMvs48e3fv0_ugj-vm9X_zRitoeN03eNndf8_vN3Z_-iXVeX9M759yi-ujRzuijJbX76V-EL7Z3Ce7e9qJYjn-6-eiXfP-XfP-X_D_GEReKkwAAAA%3d%3d"></script>
<script type="text/javascript" src="/asset.axd?id=General"></script>
<script type="text/javascript" src="/asset.axd?id=Form"></script>
It would be nicer if it was like this...
<script type="text/javascript" src="/asset.axd?id=default"></script>
<script type="text/javascript" src="/asset.axd?id=General"></script>
<script type="text/javascript" src="/asset.axd?id=Form"></script>
I know I'm going on a bit, but I'm just writing down thoughts as I migrate over our code... Keep up the good work.
Cheers
Anthony

I think I have found a bug....
I have the following in my master page:
<%= Html.Telerik().StyleSheetRegistrar()
.StyleSheets(sheets => sheets.AddSharedGroup("GeneralCSS"))%>
And this in one of my controls:
<% Html.Telerik().StyleSheetRegistrar()
.StyleSheets(styles => styles.AddSharedGroup("FormCSS")); %>
The system doesn't render the style sheets that make up FormCSS.
I am using this pattern for the javascript asset groups but it doesn't seem to be working for the style sheets.
Cheers
Anthony

<%= Html.Telerik().StyleSheetRegistrar()
.StyleSheets(styles => styles.AddSharedGroup("FormCSS")); %>

Another problem that I have found is that the ScriptRegistrar doesn't seem to work within templates...
As a test I put the following in one of my EditorTemplates and nothing is rendered into the "on ready" except for whitespace:
<% Html.Telerik().ScriptRegistrar().OnDocumentReady(() => { %> alert('test'); <%}); %>
Cheers
Anthony

Thanks for the reply but I think you are incorrect...
In my example you will see that I have the following in the master page:
<%= Html.Telerik().StyleSheetRegistrar()
.StyleSheets(sheets => sheets.AddSharedGroup("GeneralCSS"))%>
The guys at telerik advised me that when you want to reference a group any time after that point, you don't use the "=" version hence why my second reference is:
<% Html.Telerik().StyleSheetRegistrar()
.StyleSheets(styles => styles.AddSharedGroup("FormCSS")); %>
And besides I know this is correct because if you type and put "=" on this one as well, it throws the following exception
You cannot call render more than once.
Cheers
Anthony

e.g
<% Html.Telerik().StyleSheetRegistrar()
.StyleSheets(sheets => sheets.AddSharedGroup("GeneralCSS"))%>
<%= Html.Telerik().StyleSheetRegistrar()
.StyleSheets(styles => styles.AddSharedGroup("FormCSS")); %>

I did a blog post on the Shared Web Asset, you may find it useful:
http://weblogs.asp.net/rashid/archive/2009/11/09/web-asset-enhancements-in-telerik-extensions-for-asp-net-mvc.aspx
Thanks,
Kazi Manzur Rashid

It answered my question about the debug options...
There are still a couple of things outstanding though -
1) Nice to have - Minify option
2) Really need - More inline code options
3) Bug - Referencing a group more than once
4) Nice to have - Ordering
5) Really need - Name of default group
6) Bug - Referencing CSS groups in controls not working
7) Bug - Using ScriptRegistrar in MVC v2 templates
Cheers
Anthony
1. There is no out of the box support, but I think you can apply the same technique that we followed in the Telerik.Web.Mvc to minify the js/css files on project build
2. I think emitting Global variables is beyond the scope of the ScriptRegistrar component. You can always use the <%= %> in your Views.
3. Group name suppose to be unique, you should only place scripts that are common, if some of the files differs, I would recommend to create another group for those cases.
4. We will give a serious thought on this feature.
5. You can access the DefaultGroup by ScriptRegisterar.DefaultGroup, you can also use ScriptRegistrar.Scripts
6. The css are only supported when you place it above of the components and the same is also true for the script, this is the limitation of the ASP.NET MVC View Engines, and the workaround requires some performance penalty, this is reason why we leave it in the current state intentionally.
7. MVC2 is not officially supported, as it is still in the development mode. We will support it once the MVC2 hits the RC.
Greetings,
Kazi Manzur Rashid
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.

1. Thats fine - as i said nice to have
2. This would be good as it means all JavaScript is at the bottom of the page. If I just use <%= %> it means JavaScript will be placed all over the place and slow down the loading of the page. Not a deal breaker though.
3. I think you misunderstood me here. I am not trying to declare 2 groups with the same name. I am simply to say that a group should be used. I give an example above. Basically, I have two controls that I am using on the same page. Each control says that it need group "Form" to be included. Hence when the page is building, it sees that you are trying to say that "Form" is needed twice. This is when it blows up. I really think this is a bug. see above I put the stack trace - message was written 22 hours ago.
4. Cheers
5. Again I mention this in the above and I am not talking about access the default group I am talking about the URL that is generated. Please see above - message was written 12 hours ago.
6. This is a really pity... I really did like the idea of having my controls say what they need and from the sounds of this I will have to have this at a page level. Meaning that the page will need to know what the controls need style wise. In the end though this may not be that bigger deal breaker as I may merge all CSS into 1 file, depending on size.
7. Dam... This is a real pain point... RC is a long time away... would it help if I said could you please sort of support templates :)
Cheers
Anthony
2. Could pls elaborate more, or may create a small sample to demostrate the issue.
5. Currently there is no way to control the id of the default group, You can turn off the default group by using the jQuery(false) then create a new shared group which should contain the required jQuery scripts.
7. We are dissussing the issue whether to support the MVC2 at this moment. in that case there would be a patch available which should work in both version.
All the best,
Kazi Manzur Rashid
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.

I would like to chip in on the subject of the Telerik’s support for the MVC 2.
Please start supporting the current pre-release version of the MVC - MVC 2 Preview 2.
Microsoft already offered a Go-Live license:
“…Visual Studio 2010 and .NET 4 Beta 2 offer developers a Go-Live license. The final release of both products is planned for March .22, 2010, according to Microsoft…”. VS2010 Beta 2 comes with MVC 2 Preview 2.
http://visualstudiomagazine.com/articles/2009/10/19/vs-2010-net-beta-4-go-live-news.aspx
Regards,
Yitzhak

Thanks for the reply.
2) I have attached a zip of a simple project that shows the example... Please not ".jpg" should be renamed to ".zip". I tried attaching the project and it seems your uploader can see past the rename. I might need to send it to an email address - do you have one that I can send it to??
5) I thought of this and in fact that is what I did at first.... but then I ran into the ordering problem I mentioned. I put my jquery script into a group called General and put that in the master page. As you probably can guess, because it was in the master page it was being rendered after any other groups that where referenced by pages or controls. This is an issue for jquery... as my other scripts expect $ to be bound to jquery. Hence the rendering order was like FormPlugins, PagePlugins and then General.
7) I totally agree with Yitzhak on this one... Reality is that MVC is go live and RC is probably at least 3 months away... If one is building controls today is seems a bit strange to say that it wont support v2 till it goes RC. I would have thought this would be a given. At the very least if you could support asset management in templates. This is a huge problem for us at the moment as we have a rather large solution and have pretty much migrated all our code over to using templates... what I ever did before templates came along I will never know. But this does make trying to use and test the Telerik asset manager extremely terdious and we have had to put in serveral work arounds to try and fix this shortcoming.
?) I had another idea. It would be great if groups could have "Group Dependencies". In that, I could say this page needs the "Form" group, where "Form" needs, "Effects" and "Controls", where both "Effects" and "Controls" need "General"... See below as an example of what I mean. Note I don't this is a must for v1 but it would certainly make using the script manager easier....
<telerik>
<webAssets>
<scripts>
<add name="General" combined="true" enabled="true">
<items>
<add source="...." />
</items>
</add>
<add name="Effects" combined="true" enabled="true" dependsOn="General">
<items>
<add source="...." />
</items>
</add>
<add name="Controls" combined="true" enabled="true" dependsOn="General">
<items>
<add source="...." />
</items>
</add>
<add name="Form" combined="true" enabled="true" dependsOn="Effects,Controls">
<items>
<add source="...." />
</items>
</add>
</scripts>
</webAssets>
</telerik>
Cheers and thanks for your time.
Anthony
Sorry for the delay pls send the attachment to rashid@telerik.com, I will take a look. Regarding the MVC2 we are working on so that our next release will support both the version.
Greetings,
Kazi Manzur Rashid
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.

Hi Kazi Manzur Rashid,
Thanks for the good news on the upcoming MVC 2 support.
Senior Program Manager, the MVC team at Microsoft, Phil Haack reports in his blog:
“…Go Live
ASP.NET MVC 2 Beta also includes an explicit go-live clause within the EULA…”
http://haacked.com/archive/2009/11/17/asp.net-mvc-2-beta-released.aspx
Regards,
Yitzhak

3. I have a group called "autocomplete" which a number of my user controls use. However If I try to add two controls which use the same "autocomplete" group onto the same page I get the error
Local group with name "autocomplete" already exists.
UPDATE:
As a work around to this, I've changed the method in WebAssetItemCollectionBuilder:
public
virtual WebAssetItemCollectionBuilder AddSharedGroup(string name)
to
if (assets.FindGroupByName(name) != null)
{
return this;
}