RT,除了调用WEBSERVICE,还可以调用页面方法,
具体怎么做?给个例子

解决方案 »

  1.   

    前提在asp.net ajax 框架下
      

  2.   

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript">
            function btnInvoke_onclick() {
                var theName = $get("helloName").value;
                PageMethods.SayHelloFromPage(theName, onSayHelloSucceeded);
            }
             
            function onSayHelloSucceeded(result) {
                $get("result").innerHTML = result;
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server" />
            <input id="helloName" type="text" />
            <input id="btnInvoke" type="button" value="Test" 
                onclick="return btnInvoke_onclick()" />
            <div id="result"></div>
        </form>
    </body>
    </html>
    [WebMethod]
        public static string SayHelloFromPage(string name)
        {
            return string.Format("Hello {0}!", name);
        }
      

  3.   

    TO LS:不知道你是否真的实现了,你连
    <Services>
            <asp:ServiceReference Path="yourpage.aspx" />
    </Services>
    都 没添加,那么你前台是怎么调用的页面方法?
      

  4.   

    我现在的问题是“PageMethods在前台未定义”
    还需要添加什么引用?