This is a migrated thread and some comments may be shown as answers.

PageMethods not defined

9 Answers 1355 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
ManniAT
Top achievements
Rank 2
ManniAT asked on 22 Apr 2009, 06:14 PM
Hi,

I have an ASPX page like this:
<head runat="server">  
    <title></title>  
        <script type="text/javascript">  
    function Test() {  
        PageMethods.TestIT();  
        alert("done");  
    }  
</script> 
 
</head> 
 
<body> 
    <form id="form1" runat="server">  
    <div> 
        <telerik:RadScriptManager runat="server" EnablePageMethods="True">  
    </telerik:RadScriptManager> 
 
<button onclick="Test(); return false;">tet</button><br />      
    </div> 
    </form> 
</body> 
</html> 
 
This runs fine.

Now I tried to achive the same thing in a masterpage like this;
<head runat="server">  
    <title></title>  
    <script type="text/javascript">  
    function Test() {  
        PageMethods.TestIT();  
        alert("done");  
    }  
</script> 
 
    <asp:ContentPlaceHolder ID="head" runat="server">  
    </asp:ContentPlaceHolder> 
</head> 
<body> 
    <form id="form1" runat="server">  
        <telerik:RadScriptManager runat="server" EnablePageMethods="True">  
    </telerik:RadScriptManager> 
 
    <div> 
    <button onclick="Test(); return false;">tet</button><br /> 
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">  
          
        </asp:ContentPlaceHolder> 
    </div> 
    </form> 
 
This results in "Microsoft JScript runtime error: 'PageMethods' is undefined"

What do I have to change to enable the things in a masterpage?

Regards

Manfred

9 Answers, 1 is accepted

Sort by
0
ManniAT
Top achievements
Rank 2
answered on 22 Apr 2009, 06:53 PM
Follow up:

First of all sorry - this post should have been placed in the Ajax section.
And one more point of precision:
If I place the [WebMethod] on the base class of my pages the things work.

The problem at all is, that when I define the method in the MasterPage code behind no script is emitted for this method call.
0
Atanas Korchev
Telerik team
answered on 23 Apr 2009, 01:19 PM
Hi ManniAT,

Does this work with the built-in ScriptManager? RadScriptManager does not do anything special with page methods. That capability is inherited from the ScriptManager control.

Best wishes,
Albert
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
ManniAT
Top achievements
Rank 2
answered on 23 Apr 2009, 01:42 PM
I guess not (I'm not 100% sure).
And the post is (to be clear) not a kind of "you bad telerik guys made" or something like this :)

It is (regardless of the reason for the problem and not asking who is guilty) just a question if someone knows if there is a way to get PageMethods out of a master pages code behind.

I know you (the telerik guys who make those things) have much more experience with these ajax things than I.
And so my hope was (is) that someone knows the problem - or even has a workaround.
Or that
Anyone can tell me: sorry no chance to get PageMethods from a method in a masterpage.

It is not a stopping issue (I made this working by using a common base class for my content pages which holds the webmethod).
So if someone has an idea - it would be great to learn it - if not don't worry.

Regards

Manfred
0
Andy
Top achievements
Rank 1
answered on 18 Feb 2010, 01:16 PM
Hi,

Did anyone find a solution to this?

Cheers
Andy
0
Fabrice Venezia
Top achievements
Rank 1
answered on 21 Jul 2010, 12:08 PM
try to put your webmethod in static mode :)
0
Caglar Duman
Top achievements
Rank 1
answered on 12 Aug 2010, 03:16 PM
I've put my webmethod in static mode. But it didn't worked..

What can be the problem? 
0
Mehmet Ali Bayraktar
Top achievements
Rank 1
answered on 12 May 2011, 09:28 AM
Instead of using Telerik's RadScriptManager, please try to use ASP.NET's Script Manager. I have used the following code:
<asp:ScriptManager ID="scrMan1" runat="server" EnablePageMethods="true" />
and I don't get the  "Microsoft JScript runtime error: 'PageMethods' is undefined" error anymore. It should be about something how Telerik handles the ScriptManger I guess.
0
Jack
Top achievements
Rank 1
answered on 01 Dec 2011, 09:45 PM
This works fine for me with Telerik's ScriptManager.  The one anomaly I did notice however is that the PageMethods enumeration will not be created if you are defining your webmethods in a user control that you load server-side.  This limitation also exists with the asp ScriptManager.  So if you need to load User Controls, either define your page webmethods in the base page or as a standard web method in a web service.
0
Mich Meow
Top achievements
Rank 1
answered on 23 Jan 2012, 04:22 PM
Hi Manfred,

I just ran into the same issue and I resolved it by changing the protection level on the WebMethod to public. Seems like the ScriptManager in the Masterpage cannot access the TestIt() method if it is Protected; however, in your first case the scriptmanager could access the protected method since it was in the page itself.

Cheers,
Andrew.
Tags
Ajax
Asked by
ManniAT
Top achievements
Rank 2
Answers by
ManniAT
Top achievements
Rank 2
Atanas Korchev
Telerik team
Andy
Top achievements
Rank 1
Fabrice Venezia
Top achievements
Rank 1
Caglar Duman
Top achievements
Rank 1
Mehmet Ali Bayraktar
Top achievements
Rank 1
Jack
Top achievements
Rank 1
Mich Meow
Top achievements
Rank 1
Share this question
or