Asp.net 从代码隐藏中获取标签值。 google 地图坐标

Asp.net getting label value from codebehind. for google maps coordinate

我无法在后面的代码中获取标签的值。我想保存 google 地图中的坐标。你能帮我看看我错过了什么吗?

HTML

 <span>Location:</span>
    <input type="text" id="txtPlaces" style="width: 250px" placeholder="Enter a location" />
    <div id="dvMap" style="width: 100%; height:300px;">
       <asp:Label ID="Label1" runat="server"></asp:Label>

          <asp:Label ID="Label2" runat="server"></asp:Label>


        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

Javascript

<script type="text/javascript">
    google.maps.event.addDomListener(window, 'load', function () {
        var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces'));
        google.maps.event.addListener(places, 'place_changed', function () {
            var place = places.getPlace();
            var address = place.formatted_address;
            var latitude = place.geometry.location.lat();
            var longitude = place.geometry.location.lng();
            var mesg = "Address: " + address;
            mesg += "\nLatitude: " + latitude;
            mesg += "\nLongitude: " + longitude;
            document.getElementById('Label1').textContent = latitude;
            document.getElementById('Label2').textContent = longitude;

            var lat = document.getElementById('Label1').textContent;
            var lon = document.getElementById('Label2').textContent;
            var mapOptions = {
                center: new google.maps.LatLng(lat, lon),
                zoom: 16,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            var infoWindow = new google.maps.InfoWindow();
            var latlngbounds = new google.maps.LatLngBounds();
            var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
            google.maps.event.addListener(map, 'click', function (e) {
                // alert("Latitude: " + e.latLng.lat() + "\r\nLongitude: " + e.latLng.lng());
            });
            alert(mesg);


        });
    });
</script>

代码隐藏

字符串示例=Label1.Text; // 或 innerhtml 或 innertext..

标签以及非输入元素的变化,例如divsspans 等,由于 HTTP Post 性质,不会发布。

我会在你的地方做的是添加一个隐藏并设置你想在那里发布的值。就像这样:

<input runat="server" ID="Label1Value" class="form-control" type="hidden" />