Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用服务器端控件获取Javascript变量的值?_Javascript_Asp.net_Vb.net - Fatal编程技术网

如何使用服务器端控件获取Javascript变量的值?

如何使用服务器端控件获取Javascript变量的值?,javascript,asp.net,vb.net,Javascript,Asp.net,Vb.net,我试图使用下面的代码来计算两个位置之间的距离 它的工作原理是显示正确的结果 结果是从位置、到位置和总英里数 我的问题是 `<asp:Label ID="results" runat="server"></asp:Label>` 在一个名为vwPersonalData的多视图控件上,单击“下一步”按钮可以在名为vwPreviewData的多视图控件上预览数据 非常感谢您的帮助 <script type="text/javascript"> var

我试图使用下面的代码来计算两个位置之间的距离

它的工作原理是显示正确的结果

结果是从位置、到位置和总英里数

我的问题是

 `<asp:Label ID="results" runat="server"></asp:Label>`
在一个名为vwPersonalData的多视图控件上,单击“下一步”按钮可以在名为vwPreviewData的多视图控件上预览数据

非常感谢您的帮助

<script type="text/javascript">

    var geocoder, location1, location2, gDir;

    function initialize() {
        geocoder = new GClientGeocoder();
        gDir = new GDirections();
        GEvent.addListener(gDir, "load", function () {
            var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
            var drivingDistanceKilometers = gDir.getDistance().meters / 1000;

            document.getElementById("results").innerHTML = '<strong>From: </strong>' + location1.address + '<br /><strong>To: </strong>' + location2.address + '<br /><strong>Driving Distance: </strong>' + drivingDistanceMiles.toFixed(2) + ' miles ';
        });
    }

    function showLocation() {
        geocoder.getLocations(document.forms[0].address1.value, function (response) {
            if (!response || response.Status.code != 200) {
                alert("Sorry, we were unable to geocode the first address");
            }
            else {
                location1 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
                geocoder.getLocations(document.forms[0].address2.value, function (response) {
                    if (!response || response.Status.code != 200) {
                        alert("Sorry, we were unable to geocode the second address");
                    }
                    else {
                        location2 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
                        gDir.load('from: ' + location1.address + ' to: ' + location2.address);
                    }
                });
            }
        });
    }

</script>
//HTML

 <asp:MultiView ID="myMultiView" ActiveViewIndex="0" runat="server">
        <asp:View ID="vwPersonalData" runat="server">
            <p>
                <asp:TextBox ID="address1" runat="server" Text="Orlando, FL" ClientIDMode="Static"></asp:TextBox>
                <asp:TextBox ID="address2" runat="server" Text="Birmingham, AL" ClientIDMode="Static"></asp:TextBox>
            </p>
             <asp:Label ID="results" runat="server" Text="" ClientIDMode="Static"></asp:Label>
        </asp:View>
      <asp:View ID="vwPreviewData" runat="server">
             <asp:Label ID="lblPreviewresults" runat="server"></asp:Label>
       </asp:view>
    </asp:MultiView>
 <asp:Button ID="btnNext" runat="server" Text="Next &gt;" OnClientClick="showLocation(); return false;" OnClick="btnNext_Click" />

只需将变量值放入隐藏字段,然后在服务器端检索隐藏字段值…@TLabel不是输入元素,所以从客户端设置为标签的值可能不会反映在服务器端。