tags:

views:

50

answers:

2

Hi,

I am using the ICallBack Interface and on the client side i need to send an object to the server method

My object is a custom javascript object Example

var person=new Object();
person.Name='Francis';
person.ID='007';

How do i pass this and decode it exaclty in the same format without using hidden fields ?

Thanks Francis P.

+2  A: 

You will need to serialize it as a string. Since the objects are simple and don't have any methods, you could use a JSON stringify function.

As for passing it to the server, if you don't want to use a hidden field, then you could use a visible field, or bypass using a form altogether and send your request by stuffing it in the query string or using XMLHttpRequest.

David Dorward
+1  A: 

What exactly is the problem with using hidden fields?

I would have serialised it into a JSON string, assigned that string to hidden form field, and that can be passed up to the server on a post where it can deserialised on the server.

The stringify function in the JSON library at http://www.json.org/js.html is propbably the most suitable for achieving this.

As for deserialising on the server, it depends on your server side language. Can you give us an indication as to this?

James Wiseman
Hi James,Thanks for the reply. Server side i use C#
Francis
In which case, you can look into using the JavaScriptSerializer class.
James Wiseman