So, after doing much searching I have found some indication that placing a Google Map inside an update panel might not always work properly. I have tried doing both; w and w/o the update panel, but have not been able to get it working. I am really wondering
if there is a hard definitive sample of somebody getting this to work properly. Now maybe our specific instance will never work, but having a place to start and reference would be greatly appreciated. Keep reading if you want to see more specifics about
the implementation...
We currently use an ASP.Net button to return some search data containing lat/longs. This information is placed into a page level string and inside the javascript there is this:
setTimeout("<%=localstring%>", 3000);
When steping through I know that the string is being filled properly before I leave the button's click event. Once completed, I right click in the page and view source and the section of the javascript code mentioned above reads:
setTimeout("", 3000);
I have tried registering the script block via the ScriptManager, but I could be wonking that up, since it is not helping. When I allow the page to refresh (normal postback) the Google Map updates and the javascript has what was stuffed into the local string.
Again, any help with this issue would be greatly appreiciated (and would help keep my sanity). Thanks.
Well after taking some time to think about the issue I have foudn a solution. May not be the best one, but it works. Here is what I did:
1. Add an ASP.Net button (may work with a different control that has a server side event link a link button, but I have not tested that)
2. Add code to register a script block (sample: ScriptManager.RegisterStartupScript(UpdatePanel1.FindControl("asp.net_button_name"),
this.GetType(),
"firendly+name", "script_block_to_inject",
true);) to the control invoking the search (for me it was a asp.net button)
3. Sit back and watch it work!
It seems ironic that I could not inject the script directly with the original button the initiated the work, but until I find something more graceful I am sticking with it.
Well it pays to let things sit for awhile and come back to them. It actually proved better to remove the DIV tag from the UpdatePanel and place it all the way back on the master page (you may just choose to put the DIV inside the asp:ContentPanel from the
master page which shoudl work just as well). We still use the LinkButton as the control for registering the Script Block with the Script Manager. And for an added bonus we threw in some code to handle null lat longs in our database. We now use the geocode
from Google to locate based on address when the lat long is null.
Have a great time trying to get you rGoogle projects to work within ASP.Net AJAX. :)
I'm having the same trouble getting my Google Map to display inside of my updatepanel. Do you think you could include more of your code so I can figure this out. I'm getting stuck on your "script_block_to_inject" part. Thanks in advance!
The code is too long to post, but here is a simplified example:
private void UpdateMap()
{
StringBuilder script_to_inject = new StringBuilder();
script_to_inject.Append("function loadMap() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(37.4419, -122.1419), 13); } }")
// add any additional scripting that should be registered - you can have as much as you like, as many functions, etc. since it will be added a a single script block to the page
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "map", script_to_inject.ToString(), true);
}
Again this is a simple example, and can be used in any server side event. You must be aware that any functions placed into the script block cannot already be on the page; it does not replace any current code. I also found that sometimes it is easier to
break down the page into simpler elements and work backwards to make sure there is not a Page_Init or Page_Load event that could cause timing problems.
NotSoBright
0 Points
15 Posts
UpdatePanel/Google Map
Jul 14, 2007 05:06 PM|LINK
So, after doing much searching I have found some indication that placing a Google Map inside an update panel might not always work properly. I have tried doing both; w and w/o the update panel, but have not been able to get it working. I am really wondering if there is a hard definitive sample of somebody getting this to work properly. Now maybe our specific instance will never work, but having a place to start and reference would be greatly appreciated. Keep reading if you want to see more specifics about the implementation...
We currently use an ASP.Net button to return some search data containing lat/longs. This information is placed into a page level string and inside the javascript there is this:
setTimeout("<%=localstring%>", 3000);
When steping through I know that the string is being filled properly before I leave the button's click event. Once completed, I right click in the page and view source and the section of the javascript code mentioned above reads:
setTimeout("", 3000);
I have tried registering the script block via the ScriptManager, but I could be wonking that up, since it is not helping. When I allow the page to refresh (normal postback) the Google Map updates and the javascript has what was stuffed into the local string.
Again, any help with this issue would be greatly appreiciated (and would help keep my sanity). Thanks.
Ajax Update panel ScriptBlocks Not Executing "Update Panel" AJAX 1.0 UpdatePanel javascript ajax update panel AsyncPostBackTrigger
albertpascua...
All-Star
17520 Points
3475 Posts
MVP
Re: UpdatePanel/Google Map
Jul 14, 2007 08:42 PM|LINK
Actually I have seen the same problem and I move the the ESRI Map Viewer, however the Microsoft Map Viewer will also work for you
This are some links that may help you if you decide to move to MS Virtual Earth http://alpascual.com/blog/al/archive/2007/03/23/How-to-use-the-Microsoft-Virtual-Earth-API.aspx
and
http://alpascual.com/blog/al/archive/2007/03/07/A-new-Map-ASP.NET-2.0-server-control-for-Virtual-Earth-mapping_2E00_.aspx
Al
My Blog
NotSoBright
0 Points
15 Posts
Re: UpdatePanel/Google Map
Jul 16, 2007 05:11 PM|LINK
Well after taking some time to think about the issue I have foudn a solution. May not be the best one, but it works. Here is what I did:
1. Add an ASP.Net button (may work with a different control that has a server side event link a link button, but I have not tested that)
2. Add code to register a script block (sample: ScriptManager.RegisterStartupScript(UpdatePanel1.FindControl("asp.net_button_name"), this.GetType(), "firendly+name", "script_block_to_inject", true);) to the control invoking the search (for me it was a asp.net button)
3. Sit back and watch it work!
It seems ironic that I could not inject the script directly with the original button the initiated the work, but until I find something more graceful I am sticking with it.
Thanks for the help!
NotSoBright
0 Points
15 Posts
Re: UpdatePanel/Google Map
Jul 26, 2007 11:53 AM|LINK
Well it pays to let things sit for awhile and come back to them. It actually proved better to remove the DIV tag from the UpdatePanel and place it all the way back on the master page (you may just choose to put the DIV inside the asp:ContentPanel from the master page which shoudl work just as well). We still use the LinkButton as the control for registering the Script Block with the Script Manager. And for an added bonus we threw in some code to handle null lat longs in our database. We now use the geocode from Google to locate based on address when the lat long is null.
Have a great time trying to get you rGoogle projects to work within ASP.Net AJAX. :)
albertpascua...
All-Star
17520 Points
3475 Posts
MVP
Re: UpdatePanel/Google Map
Jul 26, 2007 02:44 PM|LINK
Forgot, if you want to use AJAX, you can always use the ESRI Map viewer http://esri.com
Al
My Blog
lg1382
Member
69 Points
72 Posts
Re: UpdatePanel/Google Map
Feb 20, 2008 07:19 PM|LINK
I'm having the same trouble getting my Google Map to display inside of my updatepanel. Do you think you could include more of your code so I can figure this out. I'm getting stuck on your "script_block_to_inject" part. Thanks in advance!
NotSoBright
0 Points
15 Posts
Re: UpdatePanel/Google Map
Feb 29, 2008 01:00 PM|LINK
The code is too long to post, but here is a simplified example:
private void UpdateMap()
{
StringBuilder script_to_inject = new StringBuilder();
script_to_inject.Append("function loadMap() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map_canvas")); map.setCenter(new GLatLng(37.4419, -122.1419), 13); } }")
// add any additional scripting that should be registered - you can have as much as you like, as many functions, etc. since it will be added a a single script block to the page
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "map", script_to_inject.ToString(), true);
}
Again this is a simple example, and can be used in any server side event. You must be aware that any functions placed into the script block cannot already be on the page; it does not replace any current code. I also found that sometimes it is easier to break down the page into simpler elements and work backwards to make sure there is not a Page_Init or Page_Load event that could cause timing problems.
Hope this helps.