如何通过.aspx.cs文件将值传递给java srcipt [英] How to pass valu to java srcipt through .aspx.cs file

查看:77
本文介绍了如何通过.aspx.cs文件将值传递给java srcipt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function initialize() {
      var lat =?;
      var lon = ?;
      var myLatlng = new google.maps.LatLng(lat, lon) // This is used to center the map to show our markers
      var mapOptions = {
          center: myLatlng,
          zoom: 6,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
          marker: true
      };
      var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
      var marker = new google.maps.Marker({
          position: myLatlng
      });
      marker.setMap(map);
  }







我想传递价值而不是?来自aspx.cs文件




i want to pass value instead of "?" from aspx.cs file

推荐答案

您可以使用<%= variable%> 从aspx.cs获取值。变量必须在 aspx.cs 文件中公开。

例如,您可以使用: var date =<%= DateTime.Now%> ; 获取服务器时间。

另一个例子:

在你的aspx.cs中你可以编码如下:

You can use <%=variable%> to get value from aspx.cs. Variable must be public in aspx.cs file.
For example, you can use: var date="<%=DateTime.Now%>"; to get the server time.
Another example:
In your aspx.cs you can code like:
public partial class _Default : System.Web.UI.Page
{
public string CsVariable = "hello world";
}



现在你可以绑定任何js vairable Like-


And now you can bind any js vairable Like-

var javacriptVariable = "<%=CsVariable%>";



另见..

在JavaScript中访问C#变量 [ ^ ]

将C#值传递给Javascript [ ^ ]


这篇关于如何通过.aspx.cs文件将值传递给java srcipt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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