PageMethods呼叫整理

摘要:PageMethods呼叫整理

在.aspx裡透過Javascript呼叫本身所寫程序的方法:

1.頁面加上ScriptManager控制項,設定EnablePageMethods="true"。

2.編寫程序,只允許static,上面加 [System.Web.Services.WebMethod]。

    [System.Web.Services.WebMethod]
    public static string GetDate(string text)
    {
        return text + System.DateTime.Now.ToString();
        
    }

3.編寫Javascript呼叫

function GetDate(程序參數1,程序參數2.......,自定參數1,.......)
{
    PageMethods.GetDate(
程序參數1,程序參數2.......,呼叫成功後的function(success),呼叫失敗的function(failed),自定參數1.......);
}


function success(回傳值,自定參數1,.......)
{
   alert(text);
}


function failed(回傳值,自定參數1,.......)
{
  
}