PageMethods not defined

10 posts, 0 answers
  1. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 22 Apr 2009 Link to this post

    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
  2. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 22 Apr 2009 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 Apr 2009 Link to this post

    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.
  5. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 23 Apr 2009 Link to this post

    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
  6. Andy
    Andy avatar
    14 posts
    Member since:
    Jun 2009

    Posted 18 Feb 2010 Link to this post

    Hi,

    Did anyone find a solution to this?

    Cheers
    Andy
  7. Fabrice Venezia
    Fabrice Venezia avatar
    1 posts
    Member since:
    Feb 2010

    Posted 21 Jul 2010 Link to this post

    try to put your webmethod in static mode :)
  8. Caglar Duman
    Caglar Duman avatar
    10 posts
    Member since:
    Jun 2010

    Posted 12 Aug 2010 Link to this post

    I've put my webmethod in static mode. But it didn't worked..

    What can be the problem? 
  9. Mehmet Ali Bayraktar
    Mehmet Ali Bayraktar avatar
    2 posts
    Member since:
    Dec 2007

    Posted 12 May 2011 Link to this post

    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.
  10. Jack
    Jack avatar
    4 posts
    Member since:
    Feb 2011

    Posted 01 Dec 2011 Link to this post

    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.
  11. Mich Meow
    Mich Meow avatar
    6 posts
    Member since:
    Jan 2010

    Posted 23 Jan 2012 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017