Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

I have been trying to learn something very trivial but have not been able to as yet; so I now revert to your assistance.

I have this
<div id="mapDiv"  runat="server" style="....."</div>


and I've been trying to pass to it a map.setView(....) command through a linkbutton from the same page.
map = new Microsoft.Maps.Map(document.getElementById("mapDiv"))


Can you please indicate how to do this?

The closest guess from my side so far has been
ASP.NET
<asp:LinkButton ID="LinkButton1" Text="Change Location" OnClick="javascript:Loc1();" runat="server"


and
JavaScript
Loc1 = function(){map.setView(........)}


I know this is not right but don't get the wrong impression, I'm just very green at this :(

Thanks a lot,
Justin

EDIT: the code lies hereunder



ASP.NET
<table class="style1">
      <tr>
          <td>

              <h1>Geolocation demo</h1>
    <div id="mapDiv"  style="position: relati..........);">
              </div>


          </td>

          <td>

              <div id="accordion">
              <h3><a href="#">North Region</a></h3>
              <div>
   <asp:LinkButton ID="LinkButton1" Text="Location 1" OnClientClick="javascript:NT1();" runat="server"/>
                  <p>Location 2</p>
                  <p>Location 3</p>
              </div>

              </div>


          </td>
      </tr>
  </table>



  <script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>

  <script type="text/javascript">
      var map = null;
      window.onload = function ()
      {
          /* Replace YOUR_BING_MAPS_KEY with your own credentials.
          Obtain a key by signing up for a developer account at
          http://www.microsoft.com/maps/developers/ */
          var cred = "YOUR_BING_MAPS_KEY";
          // Initialize map
          map = new Microsoft.Maps.Map(document.getElementById("mapDiv"),
          { credentials: cred, showDashboard: false });
     :
     :
     :
     :

      NT1 = function ()
      {
          map.setView({ zoom: 5, center: new Microsoft.Maps.Location(35.96592, 14.344196) })
      }
</script>
Posted
Updated 12-Mar-12 7:29am
v3

1 solution

Sir;
I think you are trying to call Loc1() on the client-silde. So you would need to use the property OnClientClick instead of OnClick because OnClick adds a handler to Click event.

ASP.NET
<asp:LinkButton ID="LinkButton1" Text="Change Location" OnClientClick="javascript:Loc1();return false;" runat="server" />
 
Share this answer
 
v2
Comments
Jukatzu 12-Mar-12 8:31am    
Hi Ali,

Yes you are right, this seems to work but the map does not change location. It seems to refresh but the initial map comes back :/ I guess I would have to put the entire code in here yes? I'll try to do so from home...

Thanks a lot though,
Justin
Jukatzu 13-Mar-12 5:35am    
hi, can you review the whole code now? I had tried OnClientClick even before and the map was refreshed back to the original view :/ How can I keep the SET view?
Ali Al Omairi(Abu AlHassan) 15-Mar-12 9:09am    
Sir;
Lets analyze it logically.
the link button "LinkButton1" is rendered as an HTML anchor with href of __doPostBack(target, args) or DoPostBackWithOptiont(...) to make a post back to the page.
<a href="javascript:__doPostBack(...);">Location 1</a>
You should prevent this post back by returning false in the onclick event. just like:
<asp:LinkButton ID="LinkButton1" runat="server" Text="Location 1" OnClientClick="javascript:NT1();return false;" />
this will be rendered as:
<a href="javascript:__doPostBack(...);" onclick="javascript:NT1();return false;">Location 1</a>
Jukatzu 15-Mar-12 12:57pm    
thanks a real lot Ali! That is very well explained :) I should have no problem moving on now...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900