asp.net中的Pagemethods

问题描述 投票:10回答:1

我的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  
}
asp.net asp.net-ajax pagemethods
1个回答
27
投票

这应该适用于所有浏览器,请按照以下步骤操作:

  • 页面方法必须具有System.Web.Services.WebMethod属性。 [的WebMethod]
  • 页面方法必须是公共的。 [WebMethod]公开......
  • 页面方法必须是静态的。 [WebMethod]公共静态...
  • 页面方法必须在页面上定义(内联或代码隐藏)。它无法在控件,母版页或基页中定义。
  • ASP.NET AJAX脚本管理器必须将EnablePageMethods设置为true。

这来自一个有效的应用程序

aspx页面:

/* 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)
{

}
© www.soinside.com 2019 - 2024. All rights reserved.