Tuesday, May 14, 2024
 Popular · Latest · Hot · Upcoming
160
rated 0 times [  165] [ 5]  / answers: 1 / hits: 20478  / 10 Years ago, mon, march 17, 2014, 12:00:00

I get the exception - JavaScript runtime error: Object doesn't support property or method 'jqGrid' when I move below block from maincontent of content page to header section of master page.



<link href=../Content/jquery.jqGrid/ui.jqgrid.css rel=stylesheet />
<link href=../Content/jquery.jqGrid/jquery-ui-custom.css rel=stylesheet />
<script src=../Scripts/jquery-1.9.1.min.js></script>
<script src=../Scripts/jquery.jqGrid.js></script>
<script src=../Scripts/i18n/grid.locale-en.js></script>





It only works when I place this block in trailing section of master page.

Could someone help me understand why it works only when I place this block in trailing section of master page but not in header section?
I think this has something to do with loading dependencies and initialization of jqGrid, however I need concrete understanding.


More From » asp.net

 Answers
2

You have to wait until DOM finishes loading. Then you can apply your scripts. Since, in your master page, you are using the script at the bottom, since the parser uses top down approach, it executes the script, after the body is completed loading.



So, if you do want to put in head section, ensure that all your script is inside document.ready() function



Also , know that it is always a best practice to put all your scripts at bottom rather than at the header.



This is a good performance indicator. Also it avoids the usage of ready function



Hope this helps..


[#71952] Saturday, March 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
amari

Total Points: 736
Total Questions: 111
Total Answers: 90

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;