Abhi
Abhi

Reputation: 5557

Getting variables value in aspx page rather than code behind

Hello Guys i am having following code in my Content page of my master page

<%@ Page Title="About Us" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Description.aspx.cs" Inherits="Description" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=key&sensor=true"
            type="text/javascript"></script>
    <script type="text/javascript">

         function initialize()
         {
            if (GBrowserIsCompatible()) 
            {
                var map = new GMap2(document.getElementById("map_canvas"));
                map.setCenter(new GLatLng(20,30), 10);// I want to change these coordinates 
                map.setUIToDefault();
            }
         }

         $(document).ready(function () 
         {
            initialize();
         });

    </script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
   <div id="main">
   </div>
</asp:content>

In above code i want to fetch coordinates from code behind . I am having coordinates in code behind ex string coor = "20,30"; so inside page load event how can i put the value of this variable in java script code. Should I create a String literal there ? or something else.

Upvotes: 0

Views: 1074

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1039498

You could store them in a property and then use them:

map.setCenter(new GLatLng(<%= Lat %>, <%= Lon %>), 10);

where Lat and Lon are two public integer properties in your code behind. You could also use methods if you will.

Upvotes: 1

Related Questions