Hey nauna,
The issue is , Label is converted into span element and html elements like span and div do't have ViewState. So use HiddenField and store your value in HiddenField and get label value on PostBack.
Please refer below sample.
HTML
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?&key=AIzaSyBE1J5Pe_GZXBR_x9TXOv6TU5vtCSmEPW4"></script>
<script type="text/javascript">
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (p) {
var LatLng = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
var geocoder = geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'latLng': LatLng }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
document.getElementById('<%= hfLabelValue.ClientID %>').value = "" + results[1].formatted_address;
}
}
});
});
} else {
alert('Geo Location feature is not supported in this browser.');
}
</script>
<div>
<asp:Button Text="GetLocation" ID="btnGet" runat="server" OnClick="GetLocation" />
<asp:HiddenField ID="hfLabelValue" runat="server" />
<br />
<asp:Label ID="lblAddress" runat="server" />
</div>
Code
C#
protected void GetLocation(object sender, EventArgs e)
{
string location = hfLabelValue.Value;
lblAddress.Text = location;
}
VB.Net
Protected Sub GetLocation(sender As Object, e As System.EventArgs) Handles btnGet.Click
Dim location As String = hfLabelValue.Value
lblAddress.Text = location
End Sub
Screenshot