This is a migrated thread and some comments may be shown as answers.

ajaxRequest argument is loosing its value when passed

3 Answers 65 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 07 May 2010, 09:23 PM
I am using the ajaxRequest functionality to explicitly fire an ajax postback event from my javascript code.

I have a javascript function that generates the callback like this:
    <telerik:RadCodeBlock ID="codeBlock" runat="server"
        <script type="text/javascript"
        //<![CDATA[
        function callPostbackFunction(args)
        {
            var ajaxManager = $find("<%= RadAjaxManager1.ClientID %>");
            ajaxManager.ajaxRequest(args);
        }
        //]]> 
        </script> 
    </telerik:RadCodeBlock> 
and, a function in the server side code, like this:
    protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e) 
    { 
        String[] list; 
        list = e.Argument.Split(','); 
        String tmp; 
        for (int i = 0; i < list.Length; i++) { 
            tmp = list[i]; 
        }    
    } 

I have verified that, when the ajaxManager.ajaxRequest(args); line is executed in my client-side javascript, the value of "args" is correct (it is a comma seperated list of values).

But, when I try to access the argument in the server side code, the value in e.Argument is just a string that says "[Object object]".

I can't figure out what is causing this. Has anyone seen this behavior before? What have I done wrong? The examples I have seen, and that I am following make it look pretty simple but, I have somehow managed to make it weird.

Thanks for any help you can provide.


3 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 11 May 2010, 09:57 AM
Hello Roger,

If "[Object object]" is what you get on the server, it means args (which you pass to ajaxRequest() is an object. It needs to be of type string. You can verify this by calling alert(typeof(args)) before the ajaxRequest() call. Let me know what you get.

What ajaxRequest() does is simply call __doPostBack(this._uniqueID, args);,  meaning it performs a postback with its own UniqueID and the args you pass. args here needs to be a string.

All the best,
Veli
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Roger
Top achievements
Rank 1
answered on 11 May 2010, 02:07 PM
Thank you for your reply.

That is what I thought was happening...the argument was an object and not a string. My frustration came from the fact that I knew the argument was being created as a string.

The conversion happens when my "dialog" (RadWindow) is closed...The function I use for the OnClientClose event expects the arguments (oWnd, args) which, I believe, are both objects.

I tried using args.toString() in the onclientclose function, but, at that point the value is changed to "[Object object]" and my comma seperated string is lost.

How can I prevent the oWnd.close(arg) functionality from converting the argument to an object?

Thanks for your help.
0
Roger
Top achievements
Rank 1
answered on 11 May 2010, 02:44 PM
I know how to fix this now...I need to append a custom attribute to the object and pass it that way.

Thanks for your help. I should have realized this before I posted the support ticket.

Thanks again.
Tags
Ajax
Asked by
Roger
Top achievements
Rank 1
Answers by
Veli
Telerik team
Roger
Top achievements
Rank 1
Share this question
or