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

[Solved] Can't include JS file for view

1 Answer 101 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.
Dewey
Top achievements
Rank 1
Dewey asked on 02 Feb 2012, 12:55 AM

I am attempting to add a script for my view by declaring a second ScriptRegistrar in the view.  The view uses a layout on which the Default ScriptRegistrar resides. Here is excerpts from the rendered page:

<head>
 
    (head stuff here)
 
<script type="text/javascript" src="/Myapp/asset.axd?id=aQMAAB-..."></script>
<script type="text/javascript" src="/Myapp/Scripts/Shared/Manual.js"></script>
<script type="text/javascript">
//<![CDATA[
jQuery(document).ready(function(){
jQuery('#Dropdownlist').tDropDownList({onChange:Dropdownlist_onChange, data:[{"Text":"","Value":"0"},...]});
//]]>
</script>
 
    <script type="text/javascript" src="/Myapp/Scripts/jquery.cookie.js"></script>
    <script type="text/javascript" src="/Myapp/Scripts/jquery.validate.js"></script>
 
</head>
<body>
 
...

The error is occurring on the line that begins "jQuery('#Dropdownlist').  The error is:

"Object doesn't support property or method 'Dropdownlist_onChange'

It appears that the named function Dropdownlist_onChange in my "Manual.js" is not being loaded into the DOM.

Right now I have located the following:

@(Html.Telerik().ScriptRegistrar()
.Scripts(x => x.AddGroup("Manual",  group => group
 .Add("~/Scripts/Shared/Manual.js"))))

near the top of the view, before the dropdownlist. Why am I getting the error?

 

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 06 Feb 2012, 09:14 AM
Hi,

 Everything looks correct and should have worked. You could check if the Manual.js file is successfully downloaded by the browser using an HTTP sniffing tool (FireBug or Fiddler).

Regards,
Atanas Korchev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
General Discussions
Asked by
Dewey
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or