有没有一种方法插入的Silverlight XAML将使用ASP.NET code隐藏我的网页? [英] Is there a way to insert Silverlight XAML into my page using ASP.NET code-behind?

查看:91
本文介绍了有没有一种方法插入的Silverlight XAML将使用ASP.NET code隐藏我的网页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想在我的ASP.NET网页上创建了一些数据的一些Silverlight的图表。该办法做到这一点,无论是使用 Visifire (我现在的东西)或即将推出的 Silverlight图表,似乎是创建一些XAML,或至少一些Silverlight的对象(<一href="http://visifire.com/documentation/Visifire_Documentation/Samples/Silverlight/Silverlight_Sample.htm"相对=nofollow>想在这个Visifire样本),然后他们的东西到莫名其妙的页面。

So, I want to create some Silverlight charts from some data on my ASP.NET web page. The way to do this, either using Visifire (my current thing) or the upcoming Silverlight charting, seems to be to create some XAML, or at least some Silverlight objects (like in this Visifire sample), and then stuff them into the page somehow.

奇怪的是,要做到这一点的唯一方法似乎是通过JavaScript!也就是说,我不得不做这样的事情:

Strangely, the only way to do this seems to be through JavaScript! That is, I'd have to do something like this:

用户 - >点击按钮 - > JavaScript事件处理程序 - > AJAX调用从服务器片面的方法来获得XAML - >东西的XAML字符串到客户端片面的HTML(如<一个href="http://weblogs.asp.net/palermo4/archive/2007/11/02/video-interactive-silverlight-using-ajax.aspx"相对=nofollow>这个一般或<一href="http://visifire.com/documentation/Visifire_Documentation/Samples/Silverlight/ASP.Net_$c$c_Example.htm"相对=nofollow>这样的Visifire,具体方法)。

User -> click button -> JavaScript event handler -> AJAX call to get XAML from server-sided method -> stuff the XAML-string into the client-sided HTML (like this in general or like this for a Visifire-specific method).

这是非常违反直觉!我宁愿拥有的是做这样的事情,里面的能力 MyPage.aspx.cs

This is highly counterintuitive! What I'd much rather have is the ability to do something like this, inside MyPage.aspx.cs:

protected void MyButton_Click(object sender, EventArgs e)
{
    this.MyFictionalSilverlightControl.Xaml = this.GenerateXamlFromData();
}

这将是更加美好!我很高兴地让 MyFictionalSilverlightControl 内的的UpdatePanel ,即使它的效率不高;我只希望我能知道如何使这样一个虚构的Silverlight控件。

That would be much nicer! I'm happy to keep MyFictionalSilverlightControl inside an UpdatePanel, even though it's inefficient; I just wish I knew how to make such a fictional Silverlight control.

任何想法?或者如何做到这更好的建议?

Any ideas? Or suggestions on how to do this better?

推荐答案

我建议更AJAXy排序方法:有XAML到控制(参见HTML桥)后,JS请求XAML,然后运行插入XAML已返回由该服务器。这样,你的控制,做一个漂亮的动画/过渡到新的显示。

I'd suggest a more AJAXy sort of approach: have JS request the XAML and then runtime insert that XAML into the control (see the HTML Bridge) after the XAML has been returned from the server. That way your control could do a nice animation/transition to the new display.

不过,你可以做你想做什么:

Still, you can do what you're aiming at:

  • 巴掌的Silverlight服务器控件成你的更新面板。
  • 在写一个aspx页面生成XAML(更改文档类型,使事情变得更容易)
  • 点在.aspx页面中的Silverlight服务器控件:

  • Slap a Silverlight server control into your Update Panel.
  • Write an aspx page to generate the XAML (Change the DocType to make things easier)
  • Point the Silverlight server control at the .ASPX page:

... ASP:Silverlight的     ID =Xaml1     =服务器     来源=〜/的ClientBin / myXAMLPage.aspx     MinimumVersion =2.0.30523     宽度=100%     高度=100%>

... asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/myXAMLPage.aspx" MinimumVersion="2.0.30523" Width="100%" Height="100%">

触发在UpdatePanel做的,每当用户点击您的按钮的事情。

Trigger the UpdatePanel to do it's thing whenever a user clicks your button.

现在,每当用户点击一个按钮,更新面板(包含Silverlight控件)将被渲染,而SL控件将请求XAML文件和渲染其发现。

Now, whenever a user clicks a button, the Update Panel (containing the Silverlight control) will be rendered, and that SL control will request the XAML file and render what it finds.

确实注意到,这种方法与实例化一个XAML文件中的控制。这意味着您将无法使用管理code在Silverlight。如果你需要管理code,而不是在源代码中指定的myXAMLPage.aspx页中,指定.xap文件,然后使用initparam指定myXAMLPage.aspx。在里面你是Silverlight应用程序,下载的XAML文件(Web客户端或其他),然后用XamlReader.Load加载它,并显示出来。

Do note, this approach instantiates the control with a XAML file. This means that you won't be able to use managed code in Silverlight. If you need managed code, instead of specifying the "myXAMLPage.aspx" page in the Source, specify your .xap file and then use an initparam to specify "myXAMLPage.aspx". Inside you're Silverlight application, download the xaml file (WebClient or whatever), and then use XamlReader.Load to load it up and display it.

心连心, 埃里克

这篇关于有没有一种方法插入的Silverlight XAML将使用ASP.NET code隐藏我的网页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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