Asp.net
asp.net 中的頁面方法
我的 Pagemethod 實現在 Chrome 瀏覽器中不起作用。我在 VS 2008 中開發了 ASP.NET 3.5 Web 應用程序。
下面的程式碼在 chrome 或 Safari 中不起作用:
function FetchDataOnTabChange(ucName) { PageMethods.FetchData(ucName, OnSuccessFetchDataOnTabChange, OnErrorFetchDataOnTabChange); } function OnErrorFetchDataOnTabChange(error) { //Do something } function OnSuccessFetchDataOnTabChange(result) { //Do something }
按照以下步驟,這應該適用於所有瀏覽器:
- 頁面方法必須具有 System.Web.Services.WebMethod 屬性。$$ WebMethod $$
- 頁面方法必須是公共的。 $$ WebMethod $$上市 …
- 頁面方法必須是靜態的。 $$ WebMethod $$公共靜態…
- page 方法必須在頁面上定義(內聯或在程式碼隱藏中)。它不能在控制項、母版頁或基本頁中定義。
- ASP.NET AJAX 腳本管理器必須將 EnablePageMethods 設置為 true。
這是來自工作應用程序
頁面:
/* the script manager could also be in a master page with no issues */ <asp:ScriptManager ID="smMain" runat="server" EnablePageMethods="true" /> <script type="text/javascript"> function GetDetails(Id) { PageMethods.GetDetails(doorId); } </script>後面的程式碼:
[System.Web.Services.WebMethod] public static void GetDetails(string Id) { }