Issue with json calling method from .net page

I am using json to retrieve the company information from the database but something is not working correctly with the registration of my class:

My page source shows the following registration:

<script type="text/javascript" src="/vos/vosnet/ajaxpro/CompanyInfo,App_Web_5phg0ezg.ashx"></script>


CompanyInfo is the name of the class in my control

However, I am getting the following error:

'CompanyInfo' is undefined

Code attached below.

Any help will be appreciated.

Thanks,

HTML
------------------------

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="CompanyInfo.ascx.vb"
    ClassName="CompanyInfo" Inherits="CompanyInfo" %>
<script type="text/javascript" src="~/JavaScript/json.js"></script>
<script type="text/javascript">

    var selectedDiv = 0;

    function getCompanyInfo() {
        selectedDiv = document.getElementById("dvCompanyInfo");
        CompanyInfo.getCompanyInformation(aJaxReturnListener);
    }

    function aJaxReturnListener(response) {
        selectedDiv.innerHTML = response.value;
    }


    $(function () {

        $('#Button1').click(saveCompanyInfo);

    });


    function saveCompanyInfo() {

        var values = {};

        $("#info :input").each(function () {
            if (this.name.search(/\[\]/) > 0) //search for [] in name
            {
                if (typeof values[this.name] != "undefined") {
                    values[this.name] = values[this.name].concat([$(this).val()])
                }
                else {
                    values[this.name] = [$(this).val()];
                }
            }
            else {
                values[this.name] = $(this).val();
            }
        }
    );

        CompanyInfo.updateField(values.toJSONString(), aJaxReturnDetailsListener);

    }

    function aJaxReturnDetailsListener(response) {
        var divEx = document.getElementById("dvQry");
        divEx.innerHTML = response.value;
    }

                    
</script>
<table width="100%">
    <tr>
        <td>
            <span><b>Company Information</b></span>
        </td>
    </tr>
    <tr>
        <td>
            <div id="dvCompanyInfo">
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <div id="dvQry">
            </div>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <input type="button" id="Button1" value="Update" onclick="saveCompanyInfo();" />
        </td>
    </tr>
</table>
<script>
    getCompanyInfo()
</script>


Code behind
-------------------------------
Imports AjaxPro
Imports Newtonsoft.Json
Imports System.Text
Imports System.Runtime.Remoting.Messaging
Imports System.Reflection
Imports System.Collections.Generic



Partial Public Class CompanyInfo
    Inherits System.Web.UI.UserControl

    Private _empid As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AjaxPro.Utility.RegisterTypeForAjax(GetType(CompanyInfo))
    End Sub
    <AjaxPro.AjaxMethod()> _
    Public Function getCompanyInformation() As String
        Dim out = String.Empty
        Dim empInfo As List(Of transferFields) = EmployerInfo.getFields(empID)
        out = EmployerInfo.renderInfo(empInfo)
        Return out
    End Function

    <AjaxPro.AjaxMethod()> _
    Public Function updateField(ByVal jsonObject As String) As String
        Dim blnFirstUpdate As Boolean = False
        Dim ajaxTransfer As List(Of transferFields) = JavaScriptConvert.DeserializeObject(jsonObject, GetType(transferFields))
        Dim out As New StringBuilder
        out.Append("update emp ")
        For x = 0 To ajaxTransfer.Count - 1
            If blnFirstUpdate Then
                out.Append("set " & ajaxTransfer.Item(x).fieldName & "='" & ajaxTransfer.Item(x).fieldValue & "' ")
                blnFirstUpdate = False
            Else
                out.Append(", " & ajaxTransfer.Item(x).fieldName & "='" & ajaxTransfer.Item(x).fieldValue & "' ")
            End If
        Next
        out.Append("where col_empid='" & Me.empID & "' ")
        Return out.ToString
    End Function

#Region "Properties"

    Public Property empID() As Integer
        Get
            Return Me._empid
        End Get
        Set(ByVal value As Integer)
            Me._empid = value
        End Set
    End Property

#End Region

End Class

Open in new window

LVL 1
melinaltAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
>'CompanyInfo' is undefined

Yes, where did you declare it?

var CompanyInfo = something;
0
melinaltAuthor Commented:
leakim971:

I am registering the class on the page load of my code behind:

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        AjaxPro.Utility.RegisterTypeForAjax(GetType(CompanyInfo))
    End Sub


The registration is succesful because I look at the source page and I see it there:


<script type="text/javascript" src="/vos/vosnet/ajaxpro/CompanyInfo,App_Web_seiqds3m.ashx"></script>




0
melinaltAuthor Commented:
I noticed that, with my class, there is a file that is dynamically being registered as well.  

<script type="text/javascript" src="/vos/vosnet/ajaxpro/CompanyInfo,App_Web_seiqds3m.ashx"></script>

In this case App_Web_seiqds3m.ashx

This name changes everytime that I refresh the page.

Checking VS intellicence, I see that I can also call the RegisterTypeForAjax with a second parameter:

RegisterTypeForAjax(type as System.Type, page as system.UI.page)


I tried this:

AjaxPro.Utility.RegisterTypeForAjax(GetType(CompanyInfo), Me.Page)

But still got the error

'CompanyInfo' is undefined

And the source still shows a dynamically generated page:

<script type="text/javascript" src="/vos/vosnet/ajaxpro/CompanyInfo,App_Web_koi4dovm.ashx"></script>

0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

leakim971PluritechnicianCommented:
Ok, so check inside this file to see if you see the declaration
Replace :
<script>
    getCompanyInfo()
</script>

Open in new window

by :
<script>
window.onload = function() {
    getCompanyInfo()
}
</script>

Open in new window

0
melinaltAuthor Commented:
Paqge source still shows:

<script>
    getCompanyInfo()
</script>

I put an alert inside function it self and I got the pop-up

function getCompanyInfo() {
        alert("HERE");
        selectedDiv = document.getElementById("dvCompanyInfo");
        CompanyInfo.getCompanyInformation(aJaxReturnListener);
    }

So the function is being called successfully too.

It is just not finding my CompanyInfo class (which is registered)

0
leakim971PluritechnicianCommented:
I think CompanyInfo is "registered" too late. After the run of getCompanyInfo.
0
melinaltAuthor Commented:
This is my entire source:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="ctl00_html" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
    <script type="text/javascript" language="javascript" src="../JavaScript/jQueryLibrary/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="/vos/vosnet/ajaxpro/CompanyInfo,App_Web_5k1p5ub4.ashx"></script>
    <script type="text/javascript" src="~/JavaScript/json.js"></script>
    <script type="text/javascript">

        var selectedDiv = 0;

        function getCompanyInfo() {
            selectedDiv = document.getElementById("dvCompanyInfo");
            CompanyInfo.getCompanyInformation(aJaxReturnListener);
        }

        function aJaxReturnListener(response) {
            selectedDiv.innerHTML = response.value;
        }


        $(function () {

            $('#Button1').click(saveCompanyInfo);

        });


        function saveCompanyInfo() {

            var values = {};

            $("#info :input").each(function () {
                if (this.name.search(/\[\]/) > 0) //search for [] in name
                {
                    if (typeof values[this.name] != "undefined") {
                        values[this.name] = values[this.name].concat([$(this).val()])
                    }
                    else {
                        values[this.name] = [$(this).val()];
                    }
                }
                else {
                    values[this.name] = $(this).val();
                }
            }
    );

            CompanyInfo.updateField(values.toJSONString(), aJaxUpdateListener);

        }

        function aJaxUpdateListener(response) {
            var divEx = document.getElementById("dvQry");
            divEx.innerHTML = response.value;
        }
 
                    
    </script>
</head>
<title></title>
<body id="ctl00_bodyid">
    <form name="aspnetForm" method="post" action="employerVerification.aspx" id="aspnetForm">
    <table width="100%">
        <tr>
            <td>
                <span><b>Company Information</b></span>
            </td>
        </tr>
        <tr>
            <td>
                <div id="dvCompanyInfo">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div id="dvQry">
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" id="Button1" value="Update" onclick="saveCompanyInfo();" />
            </td>
        </tr>
    </table>
    <script>
        getCompanyInfo()
    </script>
    </form>
</body>
</html>

Open in new window

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<head>
    <script type="text/javascript" language="javascript" src="../JavaScript/jQueryLibrary/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="~/JavaScript/json.js"></script>
    <script type="text/javascript" src="/vos/vosnet/ajaxpro/CompanyInfo,App_Web_5k1p5ub4.ashx"></script>
    <script type="text/javascript">

        var selectedDiv = 0;

        function getCompanyInfo() {
            selectedDiv = document.getElementById("dvCompanyInfo");
            CompanyInfo.getCompanyInformation(aJaxReturnListener);
        }

        function aJaxReturnListener(response) {
            selectedDiv.innerHTML = response.value;
        }


        $(function () {

            $('#Button1').click(saveCompanyInfo);

        });


        function saveCompanyInfo() {

            var values = {};

            $("#info :input").each(function () {
                if (this.name.search(/\[\]/) > 0) //search for [] in name
                {
                    if (typeof values[this.name] != "undefined") {
                        values[this.name] = values[this.name].concat([$(this).val()])
                    }
                    else {
                        values[this.name] = [$(this).val()];
                    }
                }
                else {
                    values[this.name] = $(this).val();
                }
            }
    );

            CompanyInfo.updateField(values.toJSONString(), aJaxUpdateListener);

        }

        function aJaxUpdateListener(response) {
            var divEx = document.getElementById("dvQry");
            divEx.innerHTML = response.value;
        }
 
                    
    </script>
</head>
<title>
</title>
<html id="ctl00_html" xmlns="http://www.w3.org/1999/xhtml" lang="en">
<body id="ctl00_bodyid">
    <form name="aspnetForm" method="post" action="employerVerification.aspx" id="aspnetForm">
    <table width="100%">
        <tr>
            <td>
                <span><b>Company Information</b></span>
            </td>
        </tr>
        <tr>
            <td>
                <div id="dvCompanyInfo">
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div id="dvQry">
                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" id="Button1" value="Update" onclick="saveCompanyInfo();" />
            </td>
        </tr>
    </table>
    <script>
        getCompanyInfo()
    </script>
    </form>
</body>
</html>

Open in new window

0
leakim971PluritechnicianCommented:
please provide a link to the page if possible...

or try my suggestion ID:37394300
0
melinaltAuthor Commented:
Unfortunately, I won't be able to give you a link since it is inside our intranet,
I tried your suggestion but still didn't work.
I am starting to think that somehow I need to specify the namespace, however, the namespace in our app is ASP so I tried ASP.CompanyInfo and still got the error

'ASP' is is undefined



0
melinaltAuthor Commented:
OK.. Seems like my assuption is correct.

I need to add the namespace before the classname

My problem is that it doesn't seem like the application has a namespace specified

Response.Write(GetType(CompanyInfo))
Response.End()

This returns CompanyInfo  -- > Which is correct

Response.Write(GetType(CompanyInfo).Namespace)
Response.End()
<b>Returns empty</b>

Is there any other way to execute the method using jason with no namespace?
0
melinaltAuthor Commented:
It was in fact an issue with the namespace and I finally figured it out.

I defined the namespace using the AjaxNamespace (added this right before my class).

<AjaxPro.AjaxNamespace("CompanyInfo")> _
Partial Class CompanyInfo
...
End Class



AND

Added the following to the web.config file


web.config

<configuration>

    <location path="ajaxpro">
        <system.webServer>
            <handlers>
                <add verb="*" path="*.ashx" name="AjaxPro"  
                     type="AjaxPro.AjaxHandlerFactory,AjaxPro.2" />
            </handlers>
        </system.webServer>
    </location>

</configuration>


It is now  working properly.

Thanks leakim971 for all your help.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
melinaltAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 250 points for leakim971's comment http:/Q_27525068.html#37394486
Assisted answer: 0 points for melinalt's comment http:/Q_27525068.html#37395137

for the following reason:

leakim971 thanks for your help.
0
melinaltAuthor Commented:
I selected incorrect solution
0
melinaltAuthor Commented:
Thanks leakim971 for all your help.
0
leakim971PluritechnicianCommented:
you're welcome! Congrats!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.