來源網址:http://www.dotblogs.com.tw/poto/archive/2009/05/21/8506.aspx - 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();
}
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,.......)
{
}
{
PageMethods.GetDate(程序參數1,程序參數2.......,呼叫成功後的function(success),呼叫失敗的function(failed),自定參數1.......);
}
function success(回傳值,自定參數1,.......)
{
alert(text);
}
function failed(回傳值,自定參數1,.......)
{
}
全站熱搜
留言列表