0

我在 aspx.net 中编写了这段代码,它运行良好,但是当写入内容页面时,它就不行了。有谁知道为什么?注意:我使用 Artem GoogleMap 控件并在其上设置图钉,然后获取其位置。

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<artem:GoogleMap ID="GoogleMap1" runat="server" 
  EnableMapTypeControl="False" MapType="Roadmap" >        
</artem:GoogleMap>      
<artem:GoogleMarkers ID="GoogleMarkers1" runat="server" 
  TargetControlID="GoogleMap1" onclientpositionchanged="handlePositionChanged">
</artem:GoogleMarkers> 
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<asp:HiddenField ID="Hidden1" runat="server" />
<asp:Button ID="Button2" runat="server" Text="Button2" onclick="Button2_Click" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
  <ContentTemplate>
    <asp:Button ID="Button1" runat="server" Text="Split" onclick="Button1_Click" />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
  </ContentTemplate>
</asp:UpdatePanel>

<script type="text/javascript">
  var list = document.getElementById("Label1");
  function handlePositionChanged(sender, e) {
    printEvent("Position Changed", sender, e);
  }
  function printEvent(name, sender, e) {
    var position = e.latLng || sender.markers[e.index].getPosition();
    document.getElementById('Label1').innerHTML = position.lat();
    document.getElementById('Label2').innerHTML = position.lng();

    document.getElementById('<%= Hidden1.ClientID %>').value = position.lat();

  }
</script>


protected void Page_Load(object sender, EventArgs e)
{
    this.GoogleMap1.MapType = Artem.Google.UI.MapType.Roadmap;
    this.GoogleMap1.Zoom = 12;
    if (!Page.IsPostBack)
    {
        GoogleMaps.LocationServices.GoogleLocationService obj = new GoogleMaps.LocationServices.GoogleLocationService();

        GoogleMaps.LocationServices.AddressData add = new GoogleMaps.LocationServices.AddressData();
        add.City = "somewhere";
        add.Country = "somewhere";
        GoogleMaps.LocationServices.MapPoint mp = new GoogleMaps.LocationServices.MapPoint();
        mp.Latitude = 29.6248771158687;
        mp.Longitude = 52.5227701663971;
        double x = mp.Latitude;
        GoogleMaps.LocationServices.MapPoint pt = obj.GetLatLongFromAddress(add);
        GoogleMap1.Latitude = mp.Latitude;
        GoogleMap1.Longitude = mp.Longitude;
    }
}

protected void Button1_Click(object sender, EventArgs e)
{
    TextBox2.Text = Hidden1.Value;
}

protected void Button2_Click(object sender, EventArgs e)
{
    string add = TextBox1.Text;
    GeoRequest request = new GeoRequest(add);
    GeoResponse response = request.GetResponse();
    GeoLocation location = response.Results[0].Geometry.Location;
    double latitude = location.Latitude;
    double longitude = location.Longitude;
    GoogleMap1.Latitude = latitude;
    GoogleMap1.Longitude = longitude;

    Artem.Google.UI.Marker mk1 = new Artem.Google.UI.Marker();
    mk1.Draggable = true;
    mk1.Address = add;
    GoogleMarkers1.Markers.Add(mk1);
}

更新:我更改了这部分代码并且它可以工作,但不知道为什么:

document.getElementById('<%= Label1.ClientID %>').innerHTML = position.lat();
4

1 回答 1

0

我认为您需要在 Master 页面中添加 scriptmanager 标记,并在 contetn 页面中添加 scriptmanagerproxy 标记。

于 2012-08-31T20:02:50.797 回答