Is it possible to pass objects (serializable classes or other ways) to a Silverlight control through asp.net server side code?
Is it possible to pass objects (serializable classes or other ways) to a Silverlight
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, it’s going to involve serialization. Remember — your Silverlight client is disconnected from the server, just like the browser is disconnected from the server.
There is a great article here on JSON serialization to and from Silverlight. Here is the summary from the article:
Let’s start with a short introduction of what JSON is. It stands for JavaScript Object Notation and is used as an alternative of the XML. Here is a simple example for a JSON file:
{'FirstName':'Martin','LastName':'Mihaylov'}for a single objectAnd
[{'FirstName':'Martin','LastName':'Mihaylov'},{'FirstName':'Emil','LastName':'Stoychev'}]for multiple objects.It looks like an array. Depending on the object that is serialized it could look really complicated.
Serializing
In order to be serializable with DataContractJsonSerializer we have to set a [DataContract] attribute. The properites that will be used by the serialization must have [DataMember] attributes. Note: To use these attributes add a reference to System.Runtime.Serialization;
Now we are ready to begin with the serialization. Let’s create a method that takes our object as an argument and returns a string in JSON format:
Deserializing
Here is what this looks like from client code: