HLRosenberger
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?
Can you explain a bit more, what exactly you are looking for?
to include a javascript file you would need to put a <script> tag in your aspx page
<script src="path_to_file/filename .js"></scr ipt>
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.
<script src="path_to_file/filename
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.
ASKER
yes, I did this in the apsx:
<script language="javascript" type="text/javascript" src="../../Scripts/MyJavas cript.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");
}
<script language="javascript" type="text/javascript" src="../../Scripts/MyJavas
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.
Check your calling code and your js method name/signature? May be some mismacth.
ASKER
I got this to work. I did this inside the aspx:
<script type="text/javascript" id="js1" src='<% =ResolveUrl("~/Scripts/MyJ avascript. js") %>'></script>
Why does the above work , but this below does not:
<script language="javascript" type="text/javascript" src="../../Scripts/MyJavas cript.js)" ></script>
<script type="text/javascript" id="js1" src='<% =ResolveUrl("~/Scripts/MyJ
Why does the above work , but this below does not:
<script language="javascript" type="text/javascript" src="../../Scripts/MyJavas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
johny_bravo1
Yes, I do have a master page. but why does this not work?
<script language="javascript" type="text/javascript" src="../../Scripts/MyJavas cript.js)" ></script>
I do not get design time error that says it cannot find the MyJavascript.js file.
Yes, I do have a master page. but why does this not work?
<script language="javascript" type="text/javascript" src="../../Scripts/MyJavas
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?
ASKER
no... Ah, so that's why?
ASKER
Thanks.