如何在asp.net中运行'PageMethods' [英] how run 'PageMethods' in asp.net

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

问题描述

hi
i将此代码放入页面但不工作

代码:

hi i put the this code in page but don''t work
code:

 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">


<script  type="text/javascript">
          function Browser_Close() {
              //alert("jjh");
             PageMethods.Test();
          }
</script>

[System.Web.Services.WebMethod]
        
        public void Test()
        {
            HttpContext.Current.Session.Abandon();
        }



错误是:


the error is:

Error: 'PageMethods' is undefined



帮助我



已添加代码块[/编辑]


help me

Code block added[/Edit]

推荐答案

你只需将你的web方法设为静态。



You just make your webmethod as static.

System.Web.Services.WebMethod]
public static void Test()
{
   HttpContext.Current.Session.Abandon();
}





如果没有静态,那么PageMethods是从javascript引发的unfind错误。除了静态,所有剩余的部分都没问题。



If not maked it static then PageMethods is undefind error raised from javascript. Except that static, all remaining part is ok.


你需要在声明方法中放置一个静态。



You need put a static in a declaration method.

[System.Web.Services.WebMethod]

public static void Test(){
}
//The static is required, if this declaration not exist, not work properly.


这篇关于如何在asp.net中运行'PageMethods'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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