0

あなたの場所を使用して郵便番号サーバー側を決定するモバイル検索に取り組んでいますが、サーバーに送信する緯度と経度に 2 つのラベルを設定しようとすると、innerHtml が null であると主張するエラーが発生します。さらに調べると、要素は null です。これはなぜですか?

<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Search.Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script language="javascript" type="text/javascript">
    navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
    var latitude;
    var longitude;
    function foundLocation(position) {
        latitude = position.coords.latitude;
        longitude = position.coords.longitude;
        alert('Your location: ' + latitude + ', ' + longitude);
    }
    function noLocation() {
        //Do something here in the case that no location is found, or user denies access
    }
    function getLocation() {
        document.getElementById("ct100_ContentPlaceHolder1_lblLat").innerHtml = latitude;
        document.getElementById("ct100_ContentPlaceHolder1_lblLong").innerHtml = longitude;
    }
</script>   
<div data-role="page">
    <div data-role="header">
        <h1>Provider Search</h1>
    </div>
    <div data-role="content">
        <asp:Button ID="btnSearch" Text="Search" runat="server" data-role="button" OnClientClick="getLocation()" OnClick="btnSearch_Clicked"></asp:Button>
        <asp:Label ID="lblLat" runat="server"></asp:Label>
        <asp:Label ID="lblLong" runat="server"></asp:Label>
        <p></p> 

    </div>

</div>

</asp:Content>

ラベルの設定を除いて、このドキュメントのすべてが完全に機能していることに注意してください。

また、実行時に asp.net によって ID プレフィックス ct100_ContentPlaceHolder1_ が生成されます。これは、デバッグ中にページ ソースを参照することで確認できます。

何か助けはありますか?

4

1 に答える 1

2

getLocation() 関数で、次のことを試してみてください:

function getLocation() {
    $('#<%=lblLat.ClientID%>').html(latitude);
    $('#<%=lblLong.ClientID%>').html(latitude);
}

同様の方法で、両方のラベルのテキスト プロパティを設定することもできます。

function getLocation() {
    $('#<%=lblLat.ClientID%>').text(latitude);
    $('#<%=lblLong.ClientID%>').text(latitude);
}
于 2012-07-31T13:29:15.407 に答える