3 Replies - 5330 Views - Last Post: 24 February 2012 - 06:52 AM

#1 cabbae2  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 44
  • Joined: 02-March 11

Google Map not changeing with dinamic control

Posted 06 November 2011 - 01:36 PM

Hi my names Abraham and well I am trying to create a form that has at load has a google map at a predefined position. Now I want to have a drop down list box that will let me change the position in the map. The problem is every time I change the position the page just loops back to the load event and places the predefined map.

Here is my form code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="GoogleMaps._Default" %>
<%@ Register src="GoogleMapsControl.ascx" tagname="GoogleMapsControl" tagprefix="uc1" %>

<!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 runat="server">
    <title>UPR-B</title>
    <link type="text/css" rel="stylesheet" href="styles/styles.css" />  
</head>
<body>
    <div id="wrapper">
            <form id="frmGMap" runat="server" >
                <div id="gMap"> 
                    <asp:PlaceHolder ID="phGMap" runat="server"></asp:PlaceHolder>
                </div>
                
                 <asp:DropDownList ID="ddlPlace" runat="server" onselectedIndexChange="Index_Changed" AutoPostBack="true">
                    <asp:ListItem>Edificio 100</asp:ListItem>
                    <asp:ListItem>Edificio 200</asp:ListItem>
                    <asp:ListItem>Edificio 300</asp:ListItem>
                    <asp:ListItem>Edificio 400</asp:ListItem>
                    <asp:ListItem>Edificio 500</asp:ListItem>
                    <asp:ListItem>Edificio 600</asp:ListItem>
                    <asp:ListItem>Edificio 700</asp:ListItem>
                    <asp:ListItem>Edificio 800</asp:ListItem>
                    <asp:ListItem>Centro Estudiantes</asp:ListItem>
                </asp:DropDownList>
            </form> 
    </div>
</body>
</html>




Code file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace GoogleMaps
{
    public partial class _Default : System.Web.UI.Page
    {
        private GoogleMaps.GoogleMapsControl gmc;

        protected void Page_Load(object sender, EventArgs e)
        {
            gmc = (GoogleMaps.GoogleMapsControl)LoadControl("~/GoogleMapsControl.ascx");
            setMap(18.371408, -66.143643, true, "Universidad de Puerto Rico en Bayamón", "");
        }
        
        private void setMap(double latitud, double longitud, bool pushPin, string pushPinTitle, string pushPinDescription) {
            gmc.ID = "gMapID";
            gmc.MapHeight = "700px";
            gmc.MapWidth = "700px";
            gmc.zoom = 17;
            gmc.mapStyle = GoogleMaps.GoogleMapsControl.MapStyle.G_SATELLITE_MAP;

            gmc.latitude = (decimal)latitud;
            gmc.longitude = (decimal)longitud;
            gmc.pushPin = pushPin;
            gmc.pushPinTitle = pushPinTitle;
            gmc.pushPinDescription = pushPinDescription;

            phGMap.Controls.Add(gmc);
        }
        protected void Index_Changed(Object sender, EventArgs e)
        {
            
            int sel = ddlPlace.SelectedIndex + 1;

            switch (sel)
            {
                case 1:
                    { setMap(18.37093, -66.143279, true, "Edificio 100", ""); }
                    break;
                case 2:
                    { setMap(18.371785, -66.143794, true, "Edificio 200", ""); }
                    break;
                case 3:
                    { setMap(18.371235, -66.142946, true, "Edificio 300", ""); }
                    break;
                case 4:
                    { setMap(18.372029, -66.143334, true, "Edificio 400", ""); }
                    break;
                case 5:
                    { setMap(18.370762, -66.143841, true, "Edificio 500", ""); }
                    break;
                case 6:
                    { setMap(18.37093, -66.143279, true, "Edificio 600", ""); }
                    break;
                case 7:
                    { setMap(18.370599, -66.14415, true, "Edificio 700", ""); }
                    break;
                case 8:
                    { setMap(18.371411, -66.144657, true, "Edificio 800", ""); }
                    break;
                default: setMap(18.372414, -66.143994, true, "Centro Estudiantes", "");
                    break;
            }

            Response.Redirect("Default.aspx");
        }
    }
}



I included everything in my project in the zip just in case anyone wanted to try it locally.

Thanks in advance.

Attached File(s)


This post has been edited by cabbae2: 06 November 2011 - 01:38 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Google Map not changeing with dinamic control

#2 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 441
  • View blog
  • Posts: 1,488
  • Joined: 28-April 09

Re: Google Map not changeing with dinamic control

Posted 08 November 2011 - 05:26 PM

try putting an If(!IsPostBack) around the code in the page load.
Was This Post Helpful? 0
  • +
  • -

#3 cabbae2  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 44
  • Joined: 02-March 11

Re: Google Map not changeing with dinamic control

Posted 09 November 2011 - 06:48 AM

View PostNakor, on 08 November 2011 - 05:26 PM, said:

try putting an If(!IsPostBack) around the code in the page load.



Good idea will try this when i get home.
Was This Post Helpful? 0
  • +
  • -

#4 cabbae2  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 44
  • Joined: 02-March 11

Re: Google Map not changeing with dinamic control

Posted 24 February 2012 - 06:52 AM

I resolve this issue I had to ditch the custom asp.net control and use the pure javascript google map api with action listener's and custom functions.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1