Sometime the JavaScript function becomes undefined

A

AAaron123

In the master header I have
<script type="text/javascript" src="JavaScripts\OpenWindow.js"></script>

OpenWindow.js contains the function openWindow



In the body of the master I have

<a href="JavaScript:eek:penWindow('Aerial','Images/Aer..snip



When I click the anchor while the page showing is Default.aspx (which is at
the root level as is .Master) the window opens OK.

The folder JavaScripts is also at the root level and OpenWindow.js then one
level below the root.

If instead of showing Default.aspx which is at the root level I show the
page Articles/Articles.aspx I find openWindow is undefined when I click the
anchor.

Do you see what is wrong?

Thanks



project

Default.aspx

Main.Master

JavaScript(folder)

OpenWondow.js (contains function openWindow)

Articles(folder)

Articles.aspx
 
A

AAaron123

I typed JavaScript in the site map below when I should have written
JavaScripts. I revised it.
JavaScripts is at the root level. Your suggestion did not work probably
because of my typo.

So it works when the page's .aspx is at root but not when the page is in a
subfolder.

When a master is merged with a contents page I think all the file
descriptions are adjusted.

1)Right?

However, I'd guess that the quoted string containing openWindow would not be
adjusted.
<a href="JavaScript:eek:penWindow('Aerial','Images/Aer..snip..

2)Right?

Maybe it doesn't need to be "adjusted" because it's in some global
namespace?

3)Comment?


Thanks


Patrice said:
src="JavaScripts/OpenWindows.js"

So the script must in a folder that is called JavaScripts and that is in
the same folder than the current ASPX page.


See site map below. JavaScripts is in the root folder.

The anchor calling openWindows is in the master.

It work OK if the contents page is at root level but not with a contents
page that is in a subfolder.

I hope this makes more sense to you than it does to me.

Any suggestions?
 
A

AAaron123

If I do this in the master
<script type="text/javascript" src="/JavaScripts/OpenWindow.js"></script>

and this in the master

<a href="JavaScript:eek:penWindow('Aerial','Ima

I always get openWindow is undefined.



I don't think I'll have a problem adjusting the Images folder

but I don't know why it doesn't find openWindow.



Thanks a lot

ps
Without the leading slash it works ok from Default.aspx which is in the root
with the master
 
A

AAaron123

Since your last post I've been looking for my log file.
I find I am running IIS 5.1 and see that IIS 7 is around.
Is 5.1 OK for XP Pro?

I searched for all IIS files on my machine and no log showed up.
Following some Internet information I right clicked my website in IIS and
looked for the web tab but there isn't one.
So I haven't yet found the log file. I did want to check as you suggested
last time.


Patrice said:
Is your web application at the root of your web site ?

In vs2008 under Solution Explorer there is the solution and under that 3
projects.
Directly under one of them is the Default.aspx, web.config and Global.asax
files.
And the root is the last folder in that project title?
This is the folder that show in IIS properties for this site.
I'm not sure what defines the application but the above sounds like the
answer is yes.
Agree?


If your web application is the web site root you'll have to use
src="/MySubFolder/JavaScripts/OpenWindow.js".
But (I hate saying "but") MySubFolder will be different on my machine and a
host's machine - won't it?

Thanks for sticking with this
 
A

AAaron123

Your suggestion to use
"/MySubFolder/JavaScripts..." and
"/MySubFolder/Images..."
fixed it.

But the Hosting site gave me a different folder name to use.

Can't I capture that folder name and store it in a session variable?

Would that be a good way to go?

Thanks for all the help
 
M

miher

Hi,

Try to add the reference in code by putting this line into Your master pages
Load instead of the <script> block in Your markup:

Page.ClientScript.RegisterClientScriptInclude(GetType(), "scripts",
ResolveClientUrl("~/JavaScripts/OpenWindow.js"));

Hope You find this useful.
-Zsolt
 
A

AAaron123

Trying to make /MySubFolder/ work at the hosting and debugging sessions I
tried to use Request.ApplicationPath.

What can I put in the head?

I tried
<script type="text/javascript">

function rootDir()

{

return '<%=ResolveUrl(Request.ApplicationPath)%>';

//return '<%=Request.ApplicationPath%>';

}

</script >

<script type="text/javascript" src= rootDir() +
"/JavaScripts/OpenWindow.js"></script>

But that didn't work.

So I move to Global.asax

setting a session variable to Request.ApplicationPathand tried

<script type="text/javascript" src= Session("RootDir") +
"/JavaScripts/OpenWindow.js"></script>

But that didn't work either.

Does the head have to have only nonexecutable markup?





Thanks

I'm not sure if I mentioned it in a previous post but your suggestion did
work for me on my debugging station. Now I want to make it general so that
it work at the hosting site as well.
 
A

AAaron123

Boy, that looks the simplest of all. First I want to get my present approach
working then I'll try this.

Thanks a lot
 
A

AAaron123

I seem to be stuck in coming up with a way to register the script in the
head so that it works in my debug machine and in the hosting service so I
tried your approach and it appears to work well. I only tried it on my
machine but it appears that it should work on the host.

I think GetType() in your code is not sufficient. I used Page.GetType()
because of something in the msdn docs.

Thanks
 
A

AAaron123

I just want to say I've used various suggestions in this thread from all
three of you in various places in my code and everything appears to be
working find now.


Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top