1

I have an ASP.Net site with some JS files references. In my master page header I have 3 files that are always referenced and a single function

    <script src="/EPS/Scripts/jquery-1.10.0.min.js" type="text/javascript"></script>
    <script src="/EPS/Scripts/jquery-ui.min.js" type="text/javascript"></script>
    <script src="/EPS/Scripts/menu.js" type="text/javascript"></script>    

    <script language="javascript" type="text/javascript">

        function checkJavaScriptValidity() {
            document.getElementById("jsDisabled").style.visibility = 'hidden';
            document.getElementById("jsEnabled").style.visibility = 'visible';            
        }

    </script>

Then in one of my aspx pages I have some more references (also added to the page header using ContentPlaceHolders)

    *JS1*<script type="text/javascript" language="javascript" src="https://serverapi.arcgisonline.com/jsapi/arcgis/3.5"></script>       
    <script src="/EPS/Scripts/savestate.js" type="text/javascript" >   </script>
    *JS2*<script src="/EPS/EPS_Controls/wcMapControl.js" type="text/javascript" >  </script>

PROBLEM: I have a user control that uses the files I marked with JS1 and JS2 (these tags are not in the source code). When the control is loaded/used I get an error in the JS or it doesnt run. In the last couple of hours I tried a couple of things (order and place) and it didnt make a difference.

Browsers

IE8: In this current order I get error: "Microsoft JScript runtime error: 'undefined' is null or not an object" in JS1

FF v22.0 I dont get any error message (or atleast I couldnt find them) but I know that my JS didnt run

Now here is my dilemma, I used this SAME control and those SAME JS files in another test project and it works fine w/o any problems there!

Question Any clue/thoughts on why would this happen? What configurations in my project would affect/cause this?

2 Answers 2

1

Remember that when it comes to javascript, everything depends on what the browser sees - there's nothing in your server code, your project configuration, or anything else in your app which would cause the issue with javascript.

With that in mind, just run View Source on your page. My guess is your script tags are getting put in after the control, so the control is attempting to do things that are not defined yet. Once you confirm this, figure out where the content placeholder with the scripts is, and move it accordingly - it probably is in the body now, and just needs to go into the head, or at least higher in the body.

Sign up to request clarification or add additional context in comments.

2 Comments

My JS files are in the header while the control is in the body
While confirming the location of my JS files, I noticed a mistake in my control inner JS calls which would cause undefined, accepted as answer coz u pointed me in this direction
1

To ensure correct loading of external scripts use ScriptManager in the master page and ScriptManagerProxy in content pages and user controls. For example, in master page:

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
    <asp:ScriptReference Path="/EPS/Scripts/jquery-1.10.0.min.js" />
    <asp:ScriptReference Path="/EPS/Scripts/jquery-ui.min.js" />
    <asp:ScriptReference Path="/EPS/Scripts/menu.js" />
</Scripts>
</asp:ScriptManager>

In a content page

<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
<Scripts>
    <asp:ScriptReference Path="https://serverapi.arcgisonline.com/jsapi/arcgis/3.5" />
    <asp:ScriptReference Path="/EPS/Scripts/savestate.js" />
</Scripts>
</asp:ScriptManagerProxy>

3 Comments

Are you suggesting that I use the SM to register the JS files instead of having them in my HTML?
@JafarKofahi Still use HTML (ASPX markup rather) but instead of referencing <script src= in pages headers use <ScriptManager><Scripts> <ScriptManagerProxy><Scripts> section. I will post the example
interesting +1 for the new info..thnx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.