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

[Solved] Using ScriptRegistrar in Master and Content Pages

4 Answers 730 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.
aozora
Top achievements
Rank 1
aozora asked on 15 Aug 2009, 07:40 PM
Hi,
I need to register a group of common script in my Site.master, and also a specific script for one of my view, but it result in the error "You cannot call render more than once".
How can I do to use your extesions in both masterpages and views?

4 Answers, 1 is accepted

Sort by
0
Accepted
Kazi Manzur Rashid
Telerik team
answered on 17 Aug 2009, 10:34 AM
Hi aozora,

Please make sure:

1. Site.master has the ScriptRegistrar at the bottom of the page, usually before the body tag.
2. The ScriptRegistrar of Site.master will only have Render(). For example:

 <% Html.Telerik().ScriptRegistrar()  
    .Scripts(script => script.GetGroup( 
            "myGroup", 
            group => group.Add("file1.js") 
            .Add("file2") 
            .Combined(true) 
          ) 
     ) 
   .Render(); %>

3. Ensure that Content page does not have any Render() :

 <% Html.Telerik().ScriptRegistrar()  
    .Scripts(script => script.AddGroup( 
            "myGroup", 
            group => group.Add("file3.js") 
            .Add("file4")
          ) 
     ) %>
4. You have registered the HttpHandler in web.config as shown in the help.

As you can see content page is responsible for adding the group and the master page is getting the same group for adding the shared files.

Best wishes,
Kazi Manzur Rashid
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
aozora
Top achievements
Rank 1
answered on 17 Aug 2009, 08:59 PM
Great! That's works. Thanks a lot!
0
Marco Teodoro
Top achievements
Rank 1
answered on 27 Apr 2010, 01:35 PM
hello i'm trying to use the script register in master and on a user control but i'm getting this error:

You cannot call render more than once.


this is my code on masterpage
<%Html.Telerik().ScriptRegistrar().Scripts(script =>
      script.GetGroup("sg",
                group => group.Add("~/Scripts/2010.1.309/jquery-1.4.2.min.js")
                             .Add("~/Scripts/jquery/jquery.bgiframe-2.1.1.js")
                             .Add("~/Scripts/jquery/jquery.toJSON.js")
                             .Add("~/Scripts/jquery/ui/jquery.ui.core.js")
                             .Add("~/Scripts/jquery/jquery.corner.js")
                             .Add("~/Scripts/jquery/jquery.timers-1.2.js")
                             .Add("~/Scripts/jquery/idle-timer.js")
                             .Add("~/Scripts/jquery/jquery.center.js")
                             .Add("~/Scripts/jquery/jquery.gradient.js")
                             .Add("~/Scripts/jquery/jquery.checkboxtree.js")
                             .Add("~/Scripts/jquery/jquery.simpletip-1.3.1.min.js")
                             .Add("~/Scripts/jquery/ui/jquery.ui.widget.js")
                             .Add("~/Scripts/jquery/ui/jquery.ui.mouse.js")
                             .Add("~/Scripts/jquery/ui/jquery.ui.draggable.js")
                             .Add("~/Scripts/jquery/ui/jquery.ui.position.js")
                             .Add("~/Scripts/jquery/ui/jquery.ui.resizable.js")
                             .Add("~/Scripts/jquery/ui/jquery.ui.dialog.js")
                             .Add("~/Scripts/jquery/ui/jquery.effects.core.js")
                             .Add("~/Scripts/jquery/ui/jquery.effects.explode.js")
                             .Add("~/Scripts/jquery/ui/jquery.effects.fold.js")
                             .Add("~/Scripts/jquery/ui/jquery.ui.accordion.js")
                        .Combined(true)
                            )
                         )
                         .Globalization(true)
                         .Render();%>

and this is the code on user control

<%= Html.Telerik().ScriptRegistrar()  
    .Scripts(script => script.AddGroup(  
            "sg",  
            group => group.Add("~/Scripts/2010.1.309/jquery-1.4.2.min.js")
          )  
     ) %>

what i'm doing wrong?

best regards
0
Atanas Korchev
Telerik team
answered on 27 Apr 2010, 02:54 PM
Hi Marco Teodoro,

As the exception name suggests the ScriptRegistar should not be rendered more than once. The <%= %> block calls the Render() method behind the curtain to output the HTML of the ScriptRegistrar. To avoid this exception simply change this code:

<%= Html.Telerik().ScriptRegistrar()  
    .Scripts(script => script.AddGroup(  
            "sg",  
            group => group.Add("~/Scripts/2010.1.309/jquery-1.4.2.min.js")
          )  
     ) %>


to:
<% Html.Telerik().ScriptRegistrar()  
    .Scripts(script => script.AddGroup(  
            "sg",  
            group => group.Add("~/Scripts/2010.1.309/jquery-1.4.2.min.js")
          )  
     ) %>


The rule of thumb is that <%= %> expects a single statement which returns object while <% %> is for executing arbitrary code which does not return any result. This is the reason why <% %> requires the explicit call of Render() while <%= %> does not.

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.
Tags
General Discussions
Asked by
aozora
Top achievements
Rank 1
Answers by
Kazi Manzur Rashid
Telerik team
aozora
Top achievements
Rank 1
Marco Teodoro
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or