none
PageMethods调用页面方法返回的是整个html?? RRS feed

  • 问题

  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

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

        }


        [System.Web.Services.WebMethod]
        public static string Hello(string yourName)
        {
            return string.Format("Hello {0}", yourName);
        }
    }

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
            <input id="Button1" type="button" value="button" />
        </div>
        </form>
    </body>
    </html>
    <script type="text/javascript">
        $addHandler($get("Button1"), "click", clickFun);
        function clickFun() {
            PageMethods.Hello("五笔拼音", sucFun);
        }

        function sucFun(r) {
            alert(r);
        }
    </script>

    2015年10月3日 12:35

答案

  • 你好,

    我在我的电脑上测试了你的代码,你的代码没有问题,可以正常显示。

    我建议你可以重新打开你的Visual Studio, 如果还是不行,我建议你可以新建一个项目来测一下你的代码。

    2015年10月7日 9:25
    版主

全部回复