asp.net 中的页面方法 [英] Pagemethods in asp.net

查看:28
本文介绍了asp.net 中的页面方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Pagemethod 实现在 Chrome 浏览器中不起作用.我有在 VS 2008 中开发的 ASP.NET 3.5 Web 应用程序.

My Pagemethod implementation is not working in Chrome browser. I have ASP.NET 3.5 web application developed in VS 2008.

以下代码在 chrome 或 Safari 中不起作用:

The code below not working in chrome or Safari:

function FetchDataOnTabChange(ucName)
{ 
    PageMethods.FetchData(ucName, OnSuccessFetchDataOnTabChange, OnErrorFetchDataOnTabChange);
}

function OnErrorFetchDataOnTabChange(error)
{   
   //Do something
}

function OnSuccessFetchDataOnTabChange(result)
{
   //Do something  
}

推荐答案

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

This should work in all browsers by following the steps below:

  • 页面方法必须具有系统.Web.服务.Web方法属性.[网络方法]
  • 页面方法必须是公共的.[WebMethod] 公共...
  • 页面方法必须是静态的.[WebMethod] 公共静态...
  • 页面方法必须定义在页面(内联或在代码隐藏).无法定义在控件、母版页或基页面.
  • ASP.NET AJAX 脚本管理器必须将 EnablePageMethods 设置为 true.

这是来自一个工作应用程序

This is from a working application

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

}

这篇关于asp.net 中的页面方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆