Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0PageMethods is not defined Error when calling a WebMethodPageMethods is not defined Error when calling a WebMethod
Previous
 
Next
New Post
9/19/2008 11:55 AM
 

I receive the error "PageMethods is not defined" when calling a WebMethod from the JavaScript in the ASCX file for a custom DotNetNuke module.  The same code and markup work correctly in a stand-alone ASP.Net application.


Here is the stand-alone (NOT in DotNetNuke) ASP.Net markup, Default.aspx:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="WebMethods._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
        Current time is: <span id="LabelCurrentTime">---</span>
        <br />
        <input type="button" id="ButtonGetTime" value="Update Time" onclick="UpdateTime();" />
    </div>
    </form>
</body>
</html>

<script type="text/javascript">
    function UpdateTime() {
        PageMethods.UpdateTime(UpdateTime_OnSucceeded, UpdateTime_OnFailed);
    }

    function UpdateTime_OnSucceeded(result, userContext, methodName) {
        $get('LabelCurrentTime').innerHTML = result;
    }

    function UpdateTime_OnFailed(error, userContext, methodName) {
        $get('LabelCurrentTime').innerHTML = "An error occured.";
    }
</script>


Here is stand-alone (NOT in DotNetNuke) VB code behind, Default.aspx.vb:

Imports System.Web.Services

Partial Public Class _Default
    Inherits System.Web.UI.Page

    <WebMethod()> _
    Public Shared Function UpdateTime() As String
        Return Now.ToString()
    End Function
End Class



When I view the web page I can click the button to retrieve the current time from the server.  This is working correctly.


Here is the DotNetNuke module markup, Main.ascx:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="Main.ascx.vb" Inherits="WebMethodsModule.Main" %>
<%@ Register assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>

Current time is: <span id="LabelCurrentTime">---</span>
<br />
<input type="button" id="ButtonGetTime" value="Update Time" onclick="UpdateTime();" />

<script type="text/javascript">
    function UpdateTime() {
        PageMethods.UpdateTime(UpdateTime_OnSucceeded, UpdateTime_OnFailed);
    }

    function UpdateTime_OnSucceeded(result, userContext, methodName) {
        $get('LabelCurrentTime').innerHTML = result;
    }

    function UpdateTime_OnFailed(error, userContext, methodName) {
        $get('LabelCurrentTime').innerHTML = "An error occured.";
    }
</script>


Here is the VB code behind, Main.ascx.vb:

Imports System.Web.Services

Partial Public Class Main
    Inherits DotNetNuke.Entities.Modules.PortalModuleBase

    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If DotNetNuke.Framework.AJAX.IsInstalled Then
            Dim objScriptManager As ScriptManager
            objScriptManager = DotNetNuke.Framework.AJAX.ScriptManagerControl(Me.Page)
            objScriptManager.EnablePageMethods = True
        End If
    End Sub

    <WebMethod()> _
    Public Shared Function UpdateTime() As String
        Return Now.ToString()
    End Function
End Class



The code in the Page_Load event does not seem to have any effect.  What I am trying to do is set the DNN-generated ScriptManager's EnablePageMethods property to True.  In the stand-alone version, I am doing the following to achieve this:

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

Since DotNetNuke creates the ScriptManager, I can't create one myself.  Somehow, I must set EnablePageMethods to true in my code to cause ASP.Net to include the PageMethods object in the rendered JavaScript, but I can't find a way to do this.


The code is being compiled for .Net framework 2.0, using version 1.0 of the Microsoft AJAX Extensions.  Any help in making this work will be greatly appreciated!
 

Thanks,
Patrick Richards

 
New Post
9/23/2008 2:41 PM
 

I finally figured this out.  You apparently can't use Page Methods in DotNetNuke.  The solution was to use a web service instead.  I created a .asmx web service file within my Desktop Modules project.  I added the following code to the Page_Load method of the .ascx.vb for the web control:

        Dim objScriptManager As ScriptManager
        Dim objServiceReference As ServiceReference

        If DotNetNuke.Framework.AJAX.IsInstalled Then
            objScriptManager = ScriptManager.GetCurrent(Me.Page)
            objServiceReference = New ServiceReference
            objServiceReference.Path = ResolveUrl("WebService.asmx")
            objScriptManager.Services.Add(objServiceReference)
        End If

In the <script> section of the .ascx I call the function as NamespaceName.ClassName.FunctionName(SucceededCallback, FailedCallback).

In the .asmx.vb web service I have the following:

Imports System.Web.Services

<System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class ClassName
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function FunctionName() As String
        Return Now.ToString
    End Function
End Class
 

-Pat

 
New Post
11/20/2008 1:34 PM
 

Hi Pat,

Your thread above gave me an idea to communicate from client in a DNN module, I tried to call a webservice webmethod using client side script and I get javascript error like namespace is not defined. I assume the script manager is not generating the proxy class on the client side. Could you please look at my code and point out what is wrong.

.ASCX

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ImageViewer.ascx.vb" Inherits="Accretive.Controls.Tasks.Remittance.ImageViewer" %>
<%@ Register assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" namespace="System.Web.UI" tagprefix="asp" %>

<br /><br /><br />
Enter name : <input type="text" id="txtName" />
<br /><br /><br />
<input type="button" id="btnSave" value="Click Me" onclick="Getmyname()" />

.VB

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim objScriptManager As ScriptManager
            Dim objServiceReference As ServiceReference

            If DotNetNuke.Framework.AJAX.IsInstalled Then
                objScriptManager = ScriptManager.GetCurrent(Me.Page)
                objServiceReference = New ServiceReference
                objServiceReference.Path = ResolveUrl("LockBoxImage.asmx")
                objScriptManager.Services.Add(objServiceReference)
            End If

            Dim cscrpt As String = "function Getmyname()" & _
                                    "{" & _
                                    "   var name = $get(""txtName"").value;" & _
                                    "   Accretive.Controls.Tasks.Remittance.LockBoxImage.Getmyname(name, OnSuccess, OnFailed);" & _
                                    "}" & _
                                    "function OnSuccess(Result) {" & _
                                    "   Result);" & _
                                    "}" & _
                                    "function OnFailed(error) {" & _
                                    "   error.get_message());" & _
                                    "}" & _
                                    "function Popmsg() {" & _
                                    "   it works now!');" & _
                                    "}"

            ScriptManager.RegisterClientScriptBlock(Me.Page, Page.GetType(), "wsspt", cscrpt, True)
        End Sub

.ASMX

Imports System.Web.Services

Namespace Accretive.Controls.Tasks.Remittance

    ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <ToolboxItem(False)> _
    Public Class LockBoxImage
        Inherits System.Web.Services.WebService

        <WebMethod()> _
        Public Function Getmyname(ByVal Nme As String) As String
            Return Nme & " you click at " & Date.Now.ToString
        End Function

    End Class

End Namespace

FYI, the webservice it located on the same folder and support partial rendering is enabled for this module. When I click the button I get a javascript error as below.

Error: 'Accretive' is undefined.

Your help will be highly appreciated!

Thanks,

Vinoth

 
New Post
11/20/2008 3:34 PM
 

Hi Patrick,

It worked for me. It was me did a mistake, the .asmx file was inherting to a wrong path.

Thank you!

Vinoth

 

 
New Post
2/23/2010 1:13 AM
 

Hi,

I am facing the same problem like "customlogin is not defined" where as customlogin is my namespace.

What will be the solution you got for this...?

 

Thanks and Regards

Sandeep Sharma

 

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0PageMethods is not defined Error when calling a WebMethodPageMethods is not defined Error when calling a WebMethod


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out