我如何初始化Silverlight控件,而无需使用Web服务调用 [英] How do I initialise a silverlight control without using web service call

查看:102
本文介绍了我如何初始化Silverlight控件,而无需使用Web服务调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个asp.net MVC Web应用程序,使多使用jQuery和渐进增强的原则。

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

我有一个复杂的控制(使用在众多的类反射),需要为了访问.NET code到功能的要求。该选择是复制在JavaScript这个code(自动生成如果可能的话),或者使用Silverlight。我将与Silverlight的选项(至少V1)。

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).

我控制的pre-的Silverlight版本开始生活由jQuery的修改成更丰富的版本,一些简单的HTML元素。不过,我已经看到了Silverlight控件的例子,一旦在页面加载得到他们的数据都喊回服务器。或者,如果这个数据是简单的,它使用initParams在参数。

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.

我的初始化数据要复杂得多,我认为initParams在可以工作,我不想再打到服务器,因为我已经有这个数据。

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?

推荐答案

您可以把任何你想要到initParams在。这仅仅是一个字符串,但如果你有一个复杂的对象,你想传递给Silverlight控件,那么你可以序列化对象转换成字符串,就捶成initParams在,然后Silverlight控件中的反序列化。

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.

另外,你知道,你可以从JavaScript中的Silverlight控件沟通到托管code(函数必须标有ScriptableMember属性)?

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)?

更何况,你不应该从Silverlight控件回WCF或ASMX Web服务调用担心 - 在我的经验中调用是非常快的,除非你是传输数据的大量

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.

这篇关于我如何初始化Silverlight控件,而无需使用Web服务调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆