ScriptManager的EnablePageMethods属性用于设定客户端javascript直接调用服务端静态WebMethod

EnablePageMethods.aspx

<script type="text/javascript">
        var txtName;
        var lblMsg;
        function pageLoad(){
            txtName=new Sys.Preview.UI.TextBox($get('txtName'));
            lblMsg=new Sys.Preview.UI.Label($get('lblMsg'));
        }
        function sayHello(){
            PageMethods.SayHello(txtName.get_text(),cb_SayHello);
        }
        function cb_SayHello(result){
            lblMsg.set_text(result);
        }
    </script>

<form ></div>
    </div>
    </form>

 

EnablePageMethods.aspx.cs

[System.Web.Services.WebMethod]
    public static String SayHello(string name)
    {
        return "welcome to site " + name;
    }

 

转自:http://www.cnblogs.com/zhangtao/articles/1742128.html 

相关文章: