GetMap() works as a button event but not inline. Problem ONLY in IE

  • Thread starter Thread starter AAaron123
  • Start date Start date
A

AAaron123

If I run in Safari or FireFox on my Windows XP it works OK. But in IE7 I get
the mesage that:

IE cannot open the site http://localhost:4272/VEMap/map.aspx

If I comment out the last line of GetMap, IE does not bomb (nor do I get the
map)

With that line not commented out if I comment out:

<script type="text/javascript"> GetMap();</script>

the button btnGetMap works Ok (map displays)

I have the IE developer toolbar and firebug but don't see how they can help!

I think the fact that the button works must be a strong clue but I don't
know how to debug javascript. No breakpoints, right?

You should also know that the Map displays in the page behind the dialog box
announcing the error. As much of the page as I can see looks OK. So why is
IE complaining?



Can you figure this out?







<asp:Content ID="Content2"... this goes into the master body

<div id="VirtualMap" style="position: relative; width: 800px; height:
800px;" >

<input id="btnGetMap" type="button" value="Get Map" name="btnGetMap"
onclick="GetMap();" />

<br />



<script type="text/javascript"> GetMap();</script>

</div>

====

<asp:Content ID="Content1" ...This goes into the master head

<script type="text/javascript">

function GetMap() {

map = new VEMap('VirtualMap');

map.LoadMap(StartPoint, 4, VEMapStyle.Road, false, VEMapMode.Mode2D, true,
4);

}
 
If I run in Safari or FireFox on my Windows XP it works OK. But in IE7 I get
the mesage that:

 IE  cannot open the sitehttp://localhost:4272/VEMap/map.aspx

If I comment out the last line of GetMap, IE does not bomb (nor do I get the
map)

With that line not commented out if I comment out:

<script type="text/javascript"> GetMap();</script>

the button btnGetMap works Ok (map displays)

I have the IE developer toolbar and firebug but don't see how they can help!

I think the fact that the button works must be a strong clue but I don't
know how to debug javascript. No breakpoints, right?

You should also know that the Map displays in the page behind the dialog box
announcing the error. As much of the page as I can see looks OK. So why is
IE complaining?

Can you figure this out?

<asp:Content ID="Content2"... this goes into the master body

<div id="VirtualMap" style="position: relative; width: 800px; height:
800px;" >

<input id="btnGetMap" type="button" value="Get Map" name="btnGetMap"
onclick="GetMap();" />

<br />

<script type="text/javascript"> GetMap();</script>

</div>

====

<asp:Content ID="Content1" ...This goes into the master head

<script type="text/javascript">

function GetMap() {

map = new VEMap('VirtualMap');

map.LoadMap(StartPoint, 4, VEMapStyle.Road, false, VEMapMode.Mode2D, true,
4);

Check if you do not load it multiple times. You can also do it in js

if(map != null)
{
map.Dispose();
}

Hope this helps
 
If I run in Safari or FireFox on my Windows XP it works OK. But in IE7 I
get
the mesage that:

IE cannot open the sitehttp://localhost:4272/VEMap/map.aspx

If I comment out the last line of GetMap, IE does not bomb (nor do I get
the
map)

With that line not commented out if I comment out:

<script type="text/javascript"> GetMap();</script>

the button btnGetMap works Ok (map displays)

I have the IE developer toolbar and firebug but don't see how they can
help!

I think the fact that the button works must be a strong clue but I don't
know how to debug javascript. No breakpoints, right?

You should also know that the Map displays in the page behind the dialog
box
announcing the error. As much of the page as I can see looks OK. So why is
IE complaining?

Can you figure this out?

<asp:Content ID="Content2"... this goes into the master body

<div id="VirtualMap" style="position: relative; width: 800px; height:
800px;" >

<input id="btnGetMap" type="button" value="Get Map" name="btnGetMap"
onclick="GetMap();" />

<br />

<script type="text/javascript"> GetMap();</script>

</div>

====

<asp:Content ID="Content1" ...This goes into the master head

<script type="text/javascript">

function GetMap() {

map = new VEMap('VirtualMap');

map.LoadMap(StartPoint, 4, VEMapStyle.Road, false, VEMapMode.Mode2D, true,
4);

Check if you do not load it multiple times. You can also do it in js

if(map != null)
{
map.Dispose();
}

Hope this helps


That did not fix it. Below is what I did.
I wonder if there is something I could put into the alert that might help.

Thanks

function GetMap() {

alert("Check");

if (map != null) {

map.Dispose();

}

map = new VEMap('VirtualMap');

map.LoadMap(StartPoint, 4, VEMapStyle.Road, false, VEMapMode.Mode2D, true,
4);

}
 
Check if you do not load it multiple times. You can also do it in js

if(map != null)
   {
    map.Dispose();
   }

Hope this helps

That did not fix it. Below is what I did.
I wonder if there is something I could put into the alert that might help..

Thanks

function GetMap() {

alert("Check");

if (map != null) {

map.Dispose();

}

map = new VEMap('VirtualMap');

map.LoadMap(StartPoint, 4, VEMapStyle.Road, false, VEMapMode.Mode2D, true,
4);

}

I've tried following

--------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Virtual Earth Hello World!</title>
<!--A meta tag declaring utf-8 is required.-->
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<!--There is a single URL for the Virtual Earth JavaScript.-->
<script type="text/javascript"
src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6">
</script>
<script type="text/javascript">
var map = null;
function GetMap()
{
//The Virtual Earth constructor takes the
//ID of the DIV.
map = new VEMap("myMap");
//LoadMap() creates the map.
//Many optional parameters can be used here.
map.LoadMap();
}
</script>
</head>
<!--You must create the map after the DOM has completely loaded.-->
<body onload="GetMap();">
<!--A simple DIV is needed as the placeholder for the map.-->
<div id="myMap"
style="position:relative; width:400px; height:400px;"></div>
</body>
</html>
 
Check if you do not load it multiple times. You can also do it in js

if(map != null)
{
map.Dispose();
}

Hope this helps

That did not fix it. Below is what I did.
I wonder if there is something I could put into the alert that might help.

Thanks

function GetMap() {

alert("Check");

if (map != null) {

map.Dispose();

}

map = new VEMap('VirtualMap');

map.LoadMap(StartPoint, 4, VEMapStyle.Road, false, VEMapMode.Mode2D, true,
4);

}

I've tried following

--------------------------------------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Virtual Earth Hello World!</title>
<!--A meta tag declaring utf-8 is required.-->
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<!--There is a single URL for the Virtual Earth JavaScript.-->
<script type="text/javascript"
src="http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6">
</script>
<script type="text/javascript">
var map = null;
function GetMap()
{
//The Virtual Earth constructor takes the
//ID of the DIV.
map = new VEMap("myMap");
//LoadMap() creates the map.
//Many optional parameters can be used here.
map.LoadMap();
}
</script>
</head>
<!--You must create the map after the DOM has completely loaded.-->
<body onload="GetMap();">
<!--A simple DIV is needed as the placeholder for the map.-->
<div id="myMap"
style="position:relative; width:400px; height:400px;"></div>
</body>
</html>

-------------------------------------

It works in my IE7 without any problem. Just copy this code to a
separated file and see if it works. If it works, it means the problem
is somewhere in your code. Hope this helps



I can/t copy it as is because I'm using a master and the context file does
not contain a Body element which may be the root of the problem.

Thanks
 
It works in my IE7 without any problem. Just copy this code to a
separated file and see if it works. If it works, it means the problem
is somewhere in your code. Hope this helps

I can/t copy it as is because I'm using a master and the context file does
not contain a Body element which may be the root of the problem.

Thanks

Well, okay, it seems that's the reason. Either try to put

<script type="text/javascript"> GetMap();</script>

at the end of content page to see if it helps

or

in your masterpage aspx set id tag

<body runat="server" id="Body">

In your content page aspx:

<%@ MasterType virtualPath="MasterPage.master" %>

In your content page codebehind:

HtmlControl body = (HtmlControl)Master.FindControl("Body");
body.Attributes.Add("onload", "GetMap();");

Hope this helps
 
It works in my IE7 without any problem. Just copy this code to a
separated file and see if it works. If it works, it means the problem
is somewhere in your code. Hope this helps

I can/t copy it as is because I'm using a master and the context file does
not contain a Body element which may be the root of the problem.

Thanks

Well, okay, it seems that's the reason. Either try to put

<script type="text/javascript"> GetMap();</script>

at the end of content page to see if it helps

or

in your masterpage aspx set id tag

<body runat="server" id="Body">

In your content page aspx:

<%@ MasterType virtualPath="MasterPage.master" %>

In your content page codebehind:

HtmlControl body = (HtmlControl)Master.FindControl("Body");
body.Attributes.Add("onload", "GetMap();");

Hope this helps



I used the second suggestion and it worked great.
Thanks
 
Well, okay, it seems that's the reason. Either try to put

<script type="text/javascript"> GetMap();</script>

at the end of content page to see if it helps

or

in your masterpage aspx set id tag

<body runat="server" id="Body">

In your content page aspx:

<%@ MasterType virtualPath="MasterPage.master" %>

In your content page codebehind:

HtmlControl body = (HtmlControl)Master.FindControl("Body");
body.Attributes.Add("onload", "GetMap();");

Hope this helps

I used the second suggestion and it worked great.
Thanks

Great, glad it's all working now.
Cheers
 
Back
Top