js调用cs函数时报错,Microsoft JScript 运行时错误: 缺少对象
aspx文件
<%@ 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>
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); } }
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); } }