Ajax.Net

Hi,
I'm starting to use Ajax.Net latest version http://www.schwarz-interactive.de with ASP .Net version 1.1. I tried to follow tutorial from the page above, but never get it work. So here is my code:

test.aspx:
testtest webapps.sample.test.Message(Message_CallBack); webapps.sample.test.Message(Message_CallBack);
<%@ Page language="c#" Codebehind="test.aspx.cs" AutoEventWireup="false" Inherits="webapps.test" %>
.
.
.
javascript code in the same file:
webapps.test.Message(Message_CallBack); webapps.sample.test.Message(Message_CallBack); webapps.sample.test.Message(Message_CallBack); webapps.sample.test.Message(Message_CallBack);the code behind:
namespace webapps
{
    /// <summary>
    /// Summary description for test.
    /// </summary>
    public class test : System.Web.UI.Page
    {
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            AjaxPro.Utility.RegisterTypeForAjax(typeof(webapps.sample.test));
        }
        [AjaxPro.AjaxMethod()]
        public string Message()
        {
            return "Hello World";
        }
  
    }
}

I use Javascript Console to check the process and it always says "webapps is not defined". Actually Ajax.Net should create the Javascript variable "webapps"  that comes from the namespace. Does anyone know where the mistake is?

thanks
0
wahyu
2/24/2006 8:02:18 AM
📁 asp.net.client-side
📃 24353 articles.
⭐ 1 followers.

💬 9 Replies
👁️‍🗨️ 1469 Views

i just recently implemented this stuff at work.

a couple of things:

1. you need to change the line: AjaxPro.Utility.RegisterTypeForAjax(typeof(webapps.sample.test));
    to: AjaxPro.Utility.RegisterTypeForAjax(typeof(test));

2. when you call the ajax method from the code behind page, you don't need to use the namespace in the call... only the class.  so the javascript syntax will look like test.Message();

the javascript should look something like this:

function myFunction()

   test.Message(myFunction_callback);
}

function myFunction_callback(response)
{
   alert(response);
}

hope that helps. 

0
rachelk
2/24/2006 3:56:39 PM
Thanks. I actually tried many different ways (try and error). Now I have something like this:

Code behind:
public class test : System.Web.UI.Page
    {
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            AjaxPro.Utility.RegisterTypeForAjax(typeof(test));
        }
        [AjaxPro.AjaxMethod()]
        public string Message()
        {
            return "Hello World";
        }
}

Aspx:
function Message(){ test.Message(Message_callback); }
function Message_callback(response){ alert(response); }

and in the body I use like onclick="Message_callback()"

it comes out with a alert window but says "undefined". Because the response is nowhere defined. Is "response" a predefined variable from Ajax.Net or do I have to define it somehow.
0
wahyu
2/24/2006 5:19:07 PM

I think the onclick function should be Message(), not Message_callback().

HTH,
Ryan


Ryan Olshan
ASPInsider | Microsoft MVP, ASP.NET
http://ryanolshan.com

How to ask a question
0
StrongTypes
2/24/2006 5:30:57 PM
ryan's right.  call the Message() function.  when it gets the response, it will automatically call the message_callback(response) function with the results from the code behind call.
0
rachelk
2/24/2006 6:37:03 PM
Thanks now it works. But I need to add "value" to the response. So it looks like this: response.value
0
wahyu
2/24/2006 10:15:42 PM

Dear All,

 I have the same problem but on server only but on localhost it work good.

when i call my page

javascript error saying "test (class name) is undefined" appear.

 plz help

thanks for all

0
manhima
3/12/2007 6:31:19 PM

Try to follow this one: http://www.ajaxpro.info/quickguide.aspx

Eric


Pascarello.com | Twitter epascarello | LinkedIn
0
A1ien51
3/12/2007 7:53:51 PM

Dear sir,

I did all steps well and the site work on my pc (localhost)

but when i upload my site to server this javascript error appear

"test is undefined"

 

where test is my class

please help

thanks

0
manhima
3/14/2007 5:49:43 PM

wahyu:
function Message_callback(response){ alert(response); }
 

function Message_callback(response)
                    {
                     if (response.error!=null)
                     {
                        alert(response.error);
                           return;
                            }


Kathirvel

Please mark as Answer if this solves your problem, Let other users get benefited.


0
kathirvelmm
6/17/2008 7:22:48 AM
Reply: