日期:2014-05-17  浏览次数:20474 次

js调用cs函数时报错,Microsoft JScript 运行时错误: 缺少对象
aspx文件
C# code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="showpage.aspx.cs" Inherits="showpage" %>


<!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 runat="server">
    <title></title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
      <script type="text/javascript">     

        function addmarkers() {
            alert("add markers");
                        LoadData();
                }    

    
    </script>
</head>
<body>
    <div id="toolbar" width="100%; height:20px;" style="text-align: center">
        <input type="button" value="mark" onclick="addmarkers()"></input>
    </div>
</body>
</html>

cs文件
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


    public partial class showpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
       public void  LoadData()
        {
            string sql = "select [Lat],[Lng],[strong] from [dbo].[Test_LatLng]";
            DataTable dt = database.Query(sql);

        }

    }


求解!先谢谢大家了!

------解决方案--------------------
LZ先学一下Ajax吧
------解决方案--------------------
lz这种写法,很符合调用AjaxPro.2.dll之后写的代码,但lz可能不知AjaxPro.2.dll是什么
------解决方案--------------------
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using AjaxPro;


    public partial class showpage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
  AjaxPro.Utility.RegisterTypeForAjax(typeof(this));//注册ajax服务   
        }
 [AjaxMethod]
       public DataTable LoadData()
        {
            string sql = "select [Lat],[Lng],[strong] from [dbo].[Test_LatLng]";
            DataTable dt = database.Query(sql);

        }

    }