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

问题描述

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

代码:

hii 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]

推荐答案

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.


[System.Web.Services.WebMethod]

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


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

10-23 05:52