melinalt
asked on
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/C ompanyInfo ,App_Web_5 phg0ezg.as hx"></scri pt>
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,
My page source shows the following registration:
<script type="text/javascript" src="/vos/vosnet/ajaxpro/C
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
ASKER
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.RegisterTy peForAjax( GetType(Co mpanyInfo) )
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/C ompanyInfo ,App_Web_s eiqds3m.as hx"></scri pt>
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.RegisterTy
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/C
ASKER
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/C ompanyInfo ,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.RegisterTy peForAjax( GetType(Co mpanyInfo) , 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/C ompanyInfo ,App_Web_k oi4dovm.as hx"></scri pt>
<script type="text/javascript" src="/vos/vosnet/ajaxpro/C
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.RegisterTy
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/C
Ok, so check inside this file to see if you see the declaration
Replace :
Replace :
<script>
getCompanyInfo()
</script>
by :<script>
window.onload = function() {
getCompanyInfo()
}
</script>
ASKER
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("d vCompanyIn fo");
CompanyInfo.getCompanyInfo rmation(aJ axReturnLi stener);
}
So the function is being called successfully too.
It is just not finding my CompanyInfo class (which is registered)
<script>
getCompanyInfo()
</script>
I put an alert inside function it self and I got the pop-up
function getCompanyInfo() {
alert("HERE");
selectedDiv = document.getElementById("d
CompanyInfo.getCompanyInfo
}
So the function is being called successfully too.
It is just not finding my CompanyInfo class (which is registered)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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>
<!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>
please provide a link to the page if possible...
or try my suggestion ID:37394300
or try my suggestion ID:37394300
ASKER
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
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
ASKER
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(Com panyInfo))
Response.End()
This returns CompanyInfo -- > Which is correct
Response.Write(GetType(Com panyInfo). Namespace)
Response.End()
<b>Returns empty</b>
Is there any other way to execute the method using jason with no namespace?
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(Com
Response.End()
This returns CompanyInfo -- > Which is correct
Response.Write(GetType(Com
Response.End()
<b>Returns empty</b>
Is there any other way to execute the method using jason with no namespace?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
ASKER
I selected incorrect solution
ASKER
Thanks leakim971 for all your help.
you're welcome! Congrats!
Yes, where did you declare it?
var CompanyInfo = something;