Can Silverlight initiate Page Refreshes?

前端 未结 5 2179
-上瘾入骨i
-上瘾入骨i 2020-12-06 00:14

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

Here is a quick question for all you Silverlight gurus.

5条回答
  •  醉话见心
    2020-12-06 01:00

    Apparently you can call a JS script from Silverlight using

    HtmlPage.Window.CreateInstance
    

    or

    HtmlPage.Window.Invoke
    

    The JavaScript to refresh a page is

    location.reload(true)
    

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

    EDIT:

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

    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");
    

    As @R4cOON suggested, you can also use:

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

提交回复
热议问题