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

View specific javascript before ScriptRegistrar

1 Answer 45 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.
Dan Appleyard
Top achievements
Rank 1
Dan Appleyard asked on 24 Jan 2010, 01:15 AM
Okay, this may be a stupid question, but I am having an issue with the ASP.NET MVC extensions.  According to the Getting Started instructions, it is recommended to place Html.Telerik().ScriptRegistrar() at the bottom of the Master Page.  I want to put a $(document).ready function in a view that uses that Master Page.  When I run the page, it comes up with a javascript error telling me it does not recognize the $ used.  Now I understand that is because the $ is used before the jquery library is loaded when Html.Telerik().ScriptRegistrar() is called, but my questions is this: How can one run view specific jquery javascript when Telerik tells us to put the Html.Telerik().ScriptRegistrar() at the bottom of the Master Page?

Thanks for any advice!

1 Answer, 1 is accepted

Sort by
0
Accepted
Jeff
Top achievements
Rank 1
answered on 24 Jan 2010, 03:40 AM
All calls made on the script and style registrars are aggregated until the .Render() method is called. This means that if you have the ScriptRegistrar().Render() call at the bottom of your MaterPage, you should be able use the OnDocumentReady() function in your view.

Master Page:

<body> 
... 
<asp:ContentPlaceHolder ID="MainContent" runat="server> 
</asp:ContentPlaceHolder> 
 
<%Html.Telerik().ScriptRegistrar().Render(); %> 
</body> 

View:

<asp:Content id="Content1" ContentPlaceHolderID="MainContent" runat="server"
... 
 
<%Html.Telerik().ScriptRegistrar().OnDocumentReady(() => { %> //your javascript here <% }); %> 
 
</asp:Content> 


Please note, I have not tried this, so please let me know how it goes.
Tags
General Discussions
Asked by
Dan Appleyard
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Share this question
or