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?
LVL 1
HLRosenbergerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Johny BravoCommented:
Can you explain a bit more, what exactly you are looking for?
0
Julian HansenCommented:
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.
0
HLRosenbergerAuthor Commented:
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");
                      
      }
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Johny BravoCommented:
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.
0
HLRosenbergerAuthor Commented:
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>
0
Johny BravoCommented:
ResolveUrl is a public method of any web control and runs with respect to the location of the page (not the original master page), the link gets resolved.

You must be having a master page with this aspx.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HLRosenbergerAuthor Commented:
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.
0
Johny BravoCommented:
Is your master page is at the same location where your aspx page is?
0
HLRosenbergerAuthor Commented:
no...  Ah, so that's why?
0
HLRosenbergerAuthor Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.