page_load의 경우 geolocation (lat, long)을 db 테이블에 저장할 필요가 있습니다.asp.net codebehind의 javacript 변수에 액세스
나는이 스크립트를 사용합니다. System.Web.UI.Page
{ 보호 무효를 Page_Load (개체를 보낸 사람, EventArgs입니다 전자) {
lblloc.Visible = true;
lblloc.Text = hdnLocation.Value;
txtloc.Text = hdnLocation.Value;
}
: 여기
<body onload="getLocation()">
<p>Click the button to get your coordinates.</p>
<%--<button onclick="getLocation()">Try It</button>--%>
<p id="demo"></p>
<form id="form1" runat="server">
<div>
<p>
<asp:HiddenField ID="hdnLocation" ClientIDMode="Static" runat="server" />
<asp:Label ID="lblloc" runat="server"></asp:Label>
<asp:TextBox ID="txtloc" runat="server"></asp:TextBox>
<asp:Button ID="btnLoc" text="submit" runat="server" OnClick="btnLoc_Click" />
</p>
</div>
</form>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
$("[id*=hdnLocation]").val(position.coords.latitude + ' ' + position.coords.longitude);
// $("[id*=btnLoc]").trigger("click");
}
</script>
</body>
</html>
는 공공 부분 클래스의 getLocation 뒤에 내 코드입니다 페이지를 실행할 때 브라우저에서 검사 할 때 숨겨진 필드에 값을 가져옵니다.
그러나 뒤에 코드에서 숨겨진 필드 값에 액세스 할 수 없습니다. Response.Write는 공백이고 lblloc.text는 null입니다.
무엇이 문제 일 수 있습니다.
이 뒤에이 도움이되지 않았다 –