我可以在Asp.Net代码中获取Javascripts值 [英] Can I Get Javascripts Values In Asp.Net Code

查看:72
本文介绍了我可以在Asp.Net代码中获取Javascripts值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i有这个地图的脚本,我想在后面的代码中使用latude和longitued的值,所以我可以得到它吗?

hi
i have this scripts for maps and i want to take the value of latude and longitued in code behind so can i get it?

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
</script>

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places">
</script>

<script type="text/javascript">
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(success);
    } else {
        alert("Geo Location is not supported on your current browser!");
    }
    function success(position) {
        var lat = position.coords.latitude;
        var long = position.coords.longitude;
        var city = position.coords.locality;
        var myLatlng = new google.maps.LatLng(lat, long);
        var myOptions = {
            center: myLatlng,
            zoom: 12,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
        var marker = new google.maps.Marker({
            position: myLatlng,
            title: "lat: " + lat + " long: " + long
        });

        marker.setMap(map);
        var infowindow = new google.maps.InfoWindow({ content: "<font color="black">User Address<br /> Latitude:" + lat + "<br /> Longitude:" + long + "" });
        infowindow.open(map, marker);
    }
</script></font>

推荐答案

让我们看一个示例,将javascript中的值从一个页面传递到另一页:

1.在第一个aspx页面中,说Page1.aspx,添加:

Let see an example to pass a value from javascript from one page to another page:
1. In the first aspx page, say Page1.aspx, add:
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="Button1" runat="server"  OnClientClick="passValue2CodeBehind();" Text="Button" onclick="Button1_Click" />



2.在第一个as后面的代码中px页面,在Page_Load事件中注册一个javascript:


2. In the code behind of the first aspx page, register a javascript in the Page_Load event:

ClientScript.RegisterStartupScript(this.GetType(), "myscript", "<script language='javascript'>function passValue2CodeBehind() {  var lat='1.2345'; document.getElementById('HiddenField1').value = lat; }  </script>");



3.将此行添加到后面代码中的Button1_Click:


3. Add this line to the Button1_Click in the code behind:

Response.Redirect("~/Page2.aspx?lat=" + HiddenField1.Value);





4.创建Page2。 aspx并添加标签:



4. Create the Page2.aspx and add a label:

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



5.在Page2.aspx后面的代码的Page_Load事件中,添加:


5. In the Page_Load event of the code behind of Page2.aspx, add this:

Label1.Text = this.Request.QueryString["lat"];



现在,启动Page1.aspx以查看工作情况。


Now, launch Page1.aspx to see the working.


最简单的方法是设置HiddenFields中的经度和纬度值通过javascript然后通过Codebehind代码检索它。
Easiest way would be to set the longitude and latitude values in HiddenFields through javascript and then retrieve it through Codebehind code.


我用动态数据解决它

这个脚本document.getElementById('HiddenField1 ')。value = lat;

无法获取内部数据,它给字符串找到内部数据我找到另一个解决方案
i solve it but with dynamic data
this script document.getElementById('HiddenField1').value = lat;
can not get the inter data it give string to find inter data i find another solution


这篇关于我可以在Asp.Net代码中获取Javascripts值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆