Microsoft JScript运行时错误:'initMap'未定义

时间:2011-06-04 02:46:17

标签: javascript asp.net undefined runtime-error

visual studio会弹出一条通知,说“Microsoft JScript运行时错误:'initMap'未定义”,并指向下面包含“initMap();”的行。

注意,我已经在aspx页面中包含了对我正在使用的javascript文件的引用。

错误:(调试时来自Default.aspx [dynamic])

<script type="text/javascript">
//<![CDATA[
initMap();Sys.Application.add_init(function() {
$create(Sys.UI._Timer, {"enabled":true,"interval":4000,"uniqueID":"Timer1"}, null, null, $get("Timer1"));
});
//]]>
<

Default.aspx.cs:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (!ClientScript.IsStartupScriptRegistered("init"))
            {
                Page.ClientScript.RegisterStartupScript
                    (this.GetType(), "init", "initMap();", true);
                //"<body onload="initialize()"> "
                //"initialize();"
            }
        }
    }

Default.aspx的:

<%@ Page Title="Home Page" Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
    Inherits="MyProject._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
    ......[some stuff here]
    </style>
    <title>Home Page</title>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&region=PK"></script>
    <script type="text/javascript" src="defaultPage.js"></script>
</head>
<body> 
    <form id="form1" name="form1" runat="server">
    ..... [some stuff here]
    </form>
</body>
</html>

我的defaultPage.js文件包含以下内容:

var geocoder;
var map;
var initialLocation = new google.maps.LatLng(24.828417, 67.038445);
var browserSupportFlag = new Boolean();
var markersArray = [];
images = new Object();
images.length = 99;

function initMap() {
....[some code here]
}

....
[more functions here]

0 个答案:

没有答案