Link to home
Start Free TrialLog in
Avatar of HLRosenberger
HLRosenbergerFlag for United States of America

asked on

aspx point to javascript file

Can an aspx point to another file that has a file extension of .js and which contains javascript for that page?
Avatar of Johny Bravo
Johny Bravo

Can you explain a bit more, what exactly you are looking for?
Avatar of Julian Hansen
to include a javascript file you would need to put a <script> tag in your aspx page

<script src="path_to_file/filename.js"></script>

That is the only way in which an aspx file can be "related" to a .js file.

You will need to elaborate on what you are trying to achieve if the above does not answer your question.
Avatar of HLRosenberger

ASKER

yes, I did this in the apsx:

<script language="javascript" type="text/javascript" src="../../Scripts/MyJavascript.js)"></script>

Now, should I be able to call functions in the MyJavascript.js file from the aspx file?  That's what I want to do.  However, I have the code below in the MyJavascript.js file, but when I try to call it from the aspx I get an error,  "Error: 'TestFunction' is undefined".  I want all my javascript in its own file.


What am I missing?



function TestFunction() {
       
        alert("TestFunction");
                      
      }
There should not be any problem in calling functions in js file from your aspx.
Check your calling code and your js method name/signature? May be some mismacth.
I got this to work.  I did this inside the aspx:

<script type="text/javascript" id="js1" src='<% =ResolveUrl("~/Scripts/MyJavascript.js") %>'></script>

Why does the above work , but this below does not:

<script language="javascript" type="text/javascript" src="../../Scripts/MyJavascript.js)"></script>
ASKER CERTIFIED SOLUTION
Avatar of Johny Bravo
Johny Bravo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
johny_bravo1

Yes, I do have a master page.   but why does this not work?

<script language="javascript" type="text/javascript" src="../../Scripts/MyJavascript.js)"></script>

I do not get design time error that says it cannot find the MyJavascript.js file.
Is your master page is at the same location where your aspx page is?
no...  Ah, so that's why?
Thanks.