ScriptManager 控件调用 WebService

<script type="text/javascript" language="JavaScript">
    function OnbuttonGo_click()
    {
        requestSimpleService = WebServiceDemo.StrToString(
            document.getElementById('inputName').value,       //params
            OnRequestComplete    //Complete event
            );
        return false;
    }

    function OnRequestComplete(result) {
        alert(result);
    }
</script>

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    <Services>
        <asp:ServiceReference Path="~/WebServiceDemo.asmx" />
    </Services>
    </asp:ScriptManager>

     <input type="text" id="inputName" size=20/>
     <input id="button" type="button" value="调 用" onclick="return OnbuttonGo_click()" />

WebServiceDemo.asmx

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;


[ScriptService]
public class WebServiceDemo : System.Web.Services.WebService {

    public WebServiceDemo () {

        //如果使用设计的组件,请取消注释以下行
        //InitializeComponent();
    }

    [WebMethod]
    public string StrToString(string str)
    {
        return "WebService输出:" + str;
    }
}

posted @ 2011-07-07 14:10  荡来荡去(allen)  阅读(219)  评论(0编辑  收藏  举报