Can you post some of your additional code. You are most likely simply missing a closing parentheses within either your server-side code or your client-side code
(such as your GetMap() function).
var
geoLocationProvider = new
Microsoft.Maps.GeoLocationProvider(map);
//
Get the user's current location, set as default
geoLocationProvider.getCurrentPosition();
}
My code behind:
//
Some database retrieval
body.Attributes["onload"]
+=//
Some code to load the map
Not sure what you need to see. Its minimal code. The page is loading a map with the users location at the center. Then, after the users selects a state, the other drop down is loaded with Programs in that state. The user then selects a program, and gets
directions to the Program with push pins on a map. I am using the BingMaps API.
One of the reasons cound be body.Attributes["onload"] +=. If you were to say something such as:
body.Attributes["onload"] += "GetMap();";
You would end up with the onload attribute being "GetMap();GetMap();" since the += would concatenate whatever you have onto the existing.
The OnLoad of the body isn't always the best option to use. A better one could be the .ready() function of jQuery since it's cross-browser, and generally works much better as it runs after the DOM is loaded. Some maps require this actually because, without
the DOM being loaded fully, your div that would contain your map may not exist yet when the function tries to create the map. For info on the .ready() function check out:
http://api.jquery.com/ready/
Don't forget to mark useful responses as Answer if they helped you towards a solution.
I am calling a function in my code behind to load my map with pushpins. I need to access the body element of my asp page. I have the runat server tag in there and it the compiler doesnt complain. When I run the program, it gives me the two errors mentioned
above. I am calling my function after doing a call to SQL.
You likely have an additional closing parentheses in your Javascript that is throwing this error. Could you post your Javascript related to this?
I'd recommend using the Developer Tools (F12) within your browser, which can help you find where this error is occuring. Depending on your browser it will often display the location and associated line number that the error is occuring on.
This would actually help, if I was only using the <body onload.....> to load only one function. But, I am using the body of my page to load my map and to load another map with pushpins on it after the user performs an action. All of my code is above in an
earlier post. I cannot see where I may have an extra ')' in my code.
Mark_F
Member
106 Points
67 Posts
Accessing the onload= property of a body element
Jan 27, 2013 05:52 PM|LINK
I am trying to access the onload property of my body element. I have the runat="server tag in my code, but it is throwing an error."
Here is my code(I'm using Visual Studio 2012);
<body id="body" runat="server" onload="GetMap();">
The errors are;
Error 1: ) expected //complaining about these two lines Error 1 & 2
Error 2: Invalid expression ter ')'
I need to access this in my Code behind, which is not showing me any errors.
body.Attributes["onload"] += //some code
Can anyone give me a suggestion?? Thank you. I have never encountered this before.
Rion William...
All-Star
27138 Points
4504 Posts
Re: Accessing the onload= property of a body element
Jan 27, 2013 07:15 PM|LINK
Can you post some of your additional code. You are most likely simply missing a closing parentheses within either your server-side code or your client-side code (such as your GetMap() function).
Mark_F
Member
106 Points
67 Posts
Re: Accessing the onload= property of a body element
Jan 27, 2013 08:53 PM|LINK
My client side code is;
<body id="body" onload="GetMap();" runat="server">
<form id="form1" runat="server">
<div id="container">
<div id="right">
<table cellpadding="2" cellspacing="2" width="310px">
<tr>
<td>Select a State:</td>
<td>Select a Program:</td>
</tr>
<tr>
<td>
<asp:DropDownList ID="ddlState" runat="server" Width="150px" AutoPostBack="True" OnSelectedIndexChanged="ddlState_SelectedIndexChanged">
</asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="ddlProgram" runat="server" Width="150px" OnSelectedIndexChanged="ddlProgram_SelectedIndexChanged">
</asp:DropDownList>
</td>
</tr>
</table>
<asp:ListView ID="healthCenters" runat="server">
</asp:ListView>
</div>
<div id='myMap' style="position: relative; width: 400px; height: 400px;"></div>
<asp:Button ID="btnSearch" runat="server"Text="Search" />
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
</div>
</form>
</body>
</html>
My javascript function:
var
map = null;
function
GetMap() {
// Set the initial map and view settings
var initialViewBounds = Microsoft.Maps.LocationRect.fromCorners(new Microsoft.Maps.Location(43, -123), new Microsoft.Maps.Location(33, -113));
var options = { credentials: "MyKey", width: 400, height: 400, bounds: initialViewBounds, mapTypeId: Microsoft.Maps.MapTypeId.areial, animate: false };
// Initialize the map
map =new Microsoft.Maps.Map(document.getElementById("myMap"), options);
// Initialize the location provider
var geoLocationProvider = new Microsoft.Maps.GeoLocationProvider(map);
// Get the user's current location, set as default
geoLocationProvider.getCurrentPosition();
}
My code behind:
// Some database retrieval
body.Attributes["onload"] +=// Some code to load the map
Not sure what you need to see. Its minimal code. The page is loading a map with the users location at the center. Then, after the users selects a state, the other drop down is loaded with Programs in that state. The user then selects a program, and gets directions to the Program with push pins on a map. I am using the BingMaps API.
markfitzme
Star
14411 Points
2226 Posts
Re: Accessing the onload= property of a body element
Jan 27, 2013 09:49 PM|LINK
One of the reasons cound be body.Attributes["onload"] +=. If you were to say something such as:
body.Attributes["onload"] += "GetMap();";
You would end up with the onload attribute being "GetMap();GetMap();" since the += would concatenate whatever you have onto the existing.
The OnLoad of the body isn't always the best option to use. A better one could be the .ready() function of jQuery since it's cross-browser, and generally works much better as it runs after the DOM is loaded. Some maps require this actually because, without the DOM being loaded fully, your div that would contain your map may not exist yet when the function tries to create the map. For info on the .ready() function check out: http://api.jquery.com/ready/
Mark_F
Member
106 Points
67 Posts
Re: Accessing the onload= property of a body element
Jan 28, 2013 09:50 PM|LINK
molly_c
Participant
1590 Points
401 Posts
Re: Accessing the onload= property of a body element
Feb 01, 2013 09:39 AM|LINK
Which error do you get ?
Molly
It's time to start living the life you are imagined.
Mark_F
Member
106 Points
67 Posts
Re: Accessing the onload= property of a body element
Feb 01, 2013 07:05 PM|LINK
I keep getting this error;
) expected
And this:
invalid expression term ')'
I am calling a function in my code behind to load my map with pushpins. I need to access the body element of my asp page. I have the runat server tag in there and it the compiler doesnt complain. When I run the program, it gives me the two errors mentioned above. I am calling my function after doing a call to SQL.
Rion William...
All-Star
27138 Points
4504 Posts
Re: Accessing the onload= property of a body element
Feb 01, 2013 07:24 PM|LINK
You likely have an additional closing parentheses in your Javascript that is throwing this error. Could you post your Javascript related to this?
I'd recommend using the Developer Tools (F12) within your browser, which can help you find where this error is occuring. Depending on your browser it will often display the location and associated line number that the error is occuring on.
Cynikal
Member
506 Points
117 Posts
Re: Accessing the onload= property of a body element
Feb 01, 2013 08:33 PM|LINK
My test.aspx code:
my test.aspx.cs code:
protected void TestFunction(object sender, EventArgs e) { Response.Redirect("http://www.disney.com"); }And, sure enough. When I went to the page, it did indeed redirect me to disney.com.
I hope this helps!
Mark_F
Member
106 Points
67 Posts
Re: Accessing the onload= property of a body element
Feb 03, 2013 05:11 PM|LINK
This would actually help, if I was only using the <body onload.....> to load only one function. But, I am using the body of my page to load my map and to load another map with pushpins on it after the user performs an action. All of my code is above in an earlier post. I cannot see where I may have an extra ')' in my code.