在aspx页面中获取变量值而不是代码隐藏

时间:2011-05-07 10:02:38

标签: c# .net asp.net

Hello Guys我在母版页的内容页面中有以下代码

<%@ 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>

在上面的代码中,我想从后面的代码中获取坐标。 我在ex string coor =“20,30”后面的代码中有坐标; 内页加载事件如何将此变量的值放在java脚本代码中。 我应该在那里创建一个String文字吗?或其他什么。

1 个答案:

答案 0 :(得分:1)

您可以将它们存储在属性中然后使用它们:

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

其中Lat和Lon是后面代码中的两个公共整数属性。如果愿意,你也可以使用方法。