Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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);
  }



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

1 solution

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:
C#
public partial class _Default : System.Web.UI.Page
{
public string CsVariable = "hello world";
}

And now you can bind any js vairable Like-
JavaScript
var javacriptVariable = "<%=CsVariable%>";

Also see..
Accessing C# Variables in JavaScript[^]
Pass C# Values To Javascript[^]
 
Share this answer
 
Comments
Bama Boy 16-Aug-13 1:32am    
thnx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900