Click here to Skip to main content
15,884,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi i put the this code in page but don't work
code:
ASP
 <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:
none
Error: 'PageMethods' is undefined

help me

[Edit]Code block added[/Edit]
Posted
Updated 13-Mar-13 7:43am
v2
Comments
sri senthil kumar 13-Mar-13 9:01am    
Check this url it has some samples
http://witstuner.blogspot.in/2013/02/different-ways-of-ajax-call-in-asp.html

Method should be static
mosi98 13-Mar-13 9:55am    
it's true but in my project don't know the 'pagemethods'
Sergey Alexandrovich Kryukov 12-Apr-13 16:52pm    
I just removed 3 of your "answers". You even self-accepted them. This is cheating. Please don't do it, otherwise you can loose your account, by votes of CodeProject members.
—SA

You just make your webmethod as static.

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


If not maked it static then PageMethods is undefind error raised from javascript. Except that static, all remaining part is ok.
 
Share this answer
 
You need put a static in a declaration method.

VB
[System.Web.Services.WebMethod]

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900