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

[Solved] ScriptRegistrar & Partial Views with Telerik Controls

3 Answers 156 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.
Tim
Top achievements
Rank 1
Tim asked on 02 Feb 2012, 06:08 PM
I seem to be having a problem where the ScriptRegistrar does not render all needed js files for the included Telerik controls when there is a Telerik control in a partial view...

Using MVC3 Intranet Template and Razor syntax; added Telerik via NuGet.  (Sample project attached)
  • Layout contains stylesheet registrar and scriptregistrar statements and includes the menu control.

  • When the View (MenuOnly) has no other telerik controls, the menu renders fine.
  • When the View (ALL) has a telerik control (currency textbox in this case) and includes a parital control containing another telerik control (grid in this case), the menu renders fine.
  • When the View (MenuGrid) has only the partial control containing another telerik control (grid in this case), the script registrar fails to render the menu js files causing the menu not to operate correctly (i.e. rollovers and sub-menus when present)...

My app really need the MenuGrid scenario whereby the partial view is refreshed via AJAX...  Is this a bug in the scriptregistrar?  Is there any workaround other than adding some other telerik control to the view as in the ALL case?

-tim

3 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 18 Mar 2012, 11:33 PM
Hello,

I'm getting what appears to be the same behaviour (only in my case it's an AutoComplete element that isn't working). To make things easier (or perhaps more complicated), my name is also Tim. :)

My setup is:
1. Default MVC3 Internet Application in Visual Studio 2010
2. Telerik MVC Extensions installed via NuGet Package Manager
3. ScriptRegistrar located in _Layout.cshtml at bottom of <body>

The behaviour is:
1. AutoComplete element in view: ScriptRegistrar renders javascript file references and element works correctly
2. AutoComplete element in partial view: ScriptRegistrar does NOT render references. Element doesn't work.
3. AutoComplete element in view and AutoComplete in partial view: ScriptRegistrar renders javascript file references and both elements work correctly

I've attached the example VS2010 solution which demonstrates these three cases.

Does anyone have any idea what's going on here?

Tim (2)
0
Tim
Top achievements
Rank 1
answered on 18 Mar 2012, 11:54 PM
Hello again,

I think I've found a potential solution.

Both mine and Tim(1)'s solutions render the ScriptRegistrar in _Layout.cshtml like so:

@{
    Html.Telerik().ScriptRegistrar()
              ...
                   .Render();
}

However, if one removes the code block and the call to Render() like below, the problem is fixed. The javascript references are rendered (even when the element is only in the partial view) and the control works as expected. This is true for both my example solution and Tim(1)'s:

@Html.Telerik().ScriptRegistrar()

I have no idea why the code-block-and-render way doesn't work but this way does. Practically I guess the disadvantage to the this way is that you can't split the code over several lines to make it more readable.

Tim(2)




0
Arnold
Top achievements
Rank 2
answered on 22 Feb 2013, 09:55 PM
Hi Everyone,

I just encountered this error, too, with an application coded approximately two years ago.

Thanks for the solution, Tim! You saved me time in figuring it out.

This was my fix:
<%= Html.Telerik().ScriptRegistrar() %>

I've attached a shot of the error.

-Arnold

Tags
General Discussions
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Arnold
Top achievements
Rank 2
Share this question
or