Chris Simpson
Chris Simpson

Reputation: 7990

How do I initialise a silverlight control without using web service call

I am developing an asp.net mvc web application that makes much use of jquery and the progressive enhancement principle.

I have a requirement for a complex control that needs access to .net code in order to function (using reflection across numerous classes). The choices were to duplicate this code in javascript (auto-generate if possible), or use silverlight. I am going with the silverlight option (at least for V1).

The pre-silverlight version of my control starts life as some simple html elements that are modified by jquery into the richer version. However the examples I've seen of silverlight controls all call back to the server once the page has loaded to get their data. Or, if this data is simple, it uses the initParams parameter.

My initialisation data is much more complicated that I think initParams can work with and I don't want to call back to the server as I already have this data.

So what are my best options?

Upvotes: 1

Views: 304

Answers (2)

AnthonyWJones
AnthonyWJones

Reputation: 189457

In the scenario you describe you can use the HTMLBridge in Silverlight to call a javascript function in your page that can provide the complex data. Silverlight has libraries for handling both XML and JSON, however, Silverlight data binding becomes much more usable when you load that data into a strongly typed model.

Upvotes: 1

slugster
slugster

Reputation: 49974

You can put whatever you want into initParams. It is just a string, but if you have a complex object you want to pass to the silverlight control then you can serialize the object into a string, whack it into initParams, and then deserialize it within the silverlight control.

Alternatively, you do know that you can communicate from javascript into managed code in the silverlight control (the functions have to be marked with the ScriptableMember attribute)?

Not to mention that you shouldn't be concerned with calls from the silverlight control back to a WCF or asmx webservice - in my experience the calls are very fast unless you are transferring large quantities of data.

Upvotes: 1

Related Questions