Silverlight可以启动页面刷新吗? [英] Can Silverlight initiate Page Refreshes?

查看:80
本文介绍了Silverlight可以启动页面刷新吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:一个替代的标题可能是:我如何从Silverlight 2.0应用程序中调用javascript.

UPDATE: An alternative title for this could be: How do I call javascript from my silverlight 2.0 application.

这是所有Silverlight专家的一个简单问题.

Here is a quick question for all you Silverlight gurus.

我有一个显示秒表倒计时的Silverlight应用程序.该应用程序托管在ASP.Net Web应用程序中, 我想要做的是,当秒表达到零时,应用程序将强制刷新托管页面的服务器页面.

I have a Silverlight app that displays a stopwatch countdown. The app is hosted in an ASP.Net web application, What I want it to do is when the stopwatch hits zero, the app forces a server page refresh of the hosting page.

这可能吗?

如果是这样,是否有代码片段的机会?

If so, any chance of a code snippet?

推荐答案

HtmlPage.Window.Invoke

刷新页面的JavaScript

The JavaScript to refresh a page is

location.reload(true)

尽管我不是Silverlight或JavaScript专家,所以不确定它是否适用于所有浏览器,甚至根本不适用.

I'm not a Silverlight or JavaScript expert though, so not sure if it works in all browsers, or even at all.

Scott发表了对此答案的评论,并附有最终解决方案.

Scott posted a comment to this answer with his final solution.

他需要在ASP.Net页面上创建一个名为reload()的JavaScript客户端函数,该函数执行了location.reload(true).然后,从他的C#代码重新加载很简单:

He needed to create a JavaScript client function on the ASP.Net page called reload() that did the location.reload(true). Then it was a simple matter from his C# code to reload:

HtmlPage.Window.Invoke("reload");

按照@ R4cOON的建议,您还可以使用:

As @R4cOON suggested, you can also use:

System.Windows.Browser.HtmlPage.Document.Submit();

这篇关于Silverlight可以启动页面刷新吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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