asp.net中ajax如何在后台Pge_Load代码声明所需要用的方法?
我用的net的AJAXEnabledWeb后台代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
[ScriptService]
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public double AddTwoNumber(double a, double b)
{
return (a + b);
}
}
然后Javascript写的有<script type="text/javascript" language="javascript">
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</div>
<input id="Button1" type="button" value="AddTwoNumbersComplete" onclick="AddNumber()"/>
</form>
</body>
</html>
<script type="text/javascript" language="javascript">
function AddNumber()
{
Default2.AddTwoNumber(3.3,4.8888,AddTwoNumberComplate);
}
function AddTwoNumberComplate(result)
{
alert("Number returned:"+result);
}
</script>
但是调试运行指明Default2.AddTwoNumber(3.3,4.8888,AddTwoNumberComplate);
的Default2未定义 怎么搞的呢?