hi,I have a google map in my page an get the Lat and Lng from database and pass them to javascrip to show map!
may map and dropdownlist are in update panel
when page load , everything is OK but when user select a text from dropdownlist to show new location on map,page dosn't show any map!
Thanks very much for any HELP:)
My aspx code:
<body><style> #map_canvas { width: 980px; height: 500px; } #current { padding-top: 25px; } </style><form id="form1" runat="server"><asp:HiddenField ID="ValueHiddenField" Value="" runat="server" /><asp:HiddenField ID="ValueHiddenField2" Value="" runat="server" /><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><div><section><asp:UpdatePanel runat="server" ID="upPanel"><ContentTemplate><div id='map_canvas'></div><asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList></ContentTemplate></asp:UpdatePanel><div id="current">Nothing yet...</div><br /><br /></section></div></form><script src="jquery.min.js"></script><script src="../assets/js/jquery.js"></script><script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyChFoGoo_PYmtv5G4fbwPctWIZ2JENPEZ0&language=fa®ion=IR&callback=initMap"></script><script> var GettingValue = document.getElementById('<%=ValueHiddenField.ClientID %>').value; var GettingValue2 = document.getElementById('<%=ValueHiddenField2.ClientID %>').value; var map = new google.maps.Map(document.getElementById('map_canvas'), { zoom: 14, center: new google.maps.LatLng(GettingValue, GettingValue2), mapTypeId: google.maps.MapTypeId.TERRAIN }); var myMarker = new google.maps.Marker({ position: new google.maps.LatLng(GettingValue, GettingValue2), draggable: true }); google.maps.event.addListener(myMarker, 'dragend', function (evt) { document.getElementById('current').innerHTML = evt.latLng.lat().toFixed(3) + ',' + evt.latLng.lng().toFixed(3); }); map.setCenter(myMarker.position); myMarker.setMap(map); </script></body>
and my behind code:
EvlaarEntities db = new EvlaarEntities(); int id; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindDrpGrp(); ValueHiddenField.Value = 38.0798351.ToString(); ValueHiddenField2.Value = 46.2449312.ToString(); } } void BindDrpGrp() { DropDownList1.DataTextField = "LocationName"; DropDownList1.DataValueField = "idLocation"; DropDownList1.DataSource = db.tbl_Locations.ToList(); DropDownList1.DataBind(); DropDownList1.Items.Insert(0, new ListItem("Select", "0")); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { id = Convert.ToInt16(DropDownList1.SelectedItem.Value); tbl_Locations tbl = db.tbl_Locations.FirstOrDefault(i => i.idLocation == id); ValueHiddenField.Value = tbl.LocationLat; ValueHiddenField2.Value = tbl.LocationLng; }