Restarting the Silverlight Object with different initParams from within Silverlight

On the Silverlight forums I found out someone wants to refresh the Silverlight Object from Javascript. Basically this solution calls a Javascript function from the Silverlight environment. I though it would be a good way to make use of features available in Silverlight.js to make it easier to create the Javascript function to refresh the Silverlight Object. The strange thing was it took me a long time to get it to work. Yes this small part Javascript in the example below took me a very long time. This has all to do with using Google Chrome and Mozilla Firefox. In the end I was not able to get this working in Chrome and Firefox, I'm not sure if this is because of failing in Silverlight.js or not, but I was not even able to load an initial Silverlight Control from javascript.

The solution: One Javascript function, and a call from Silverlight to the Javascript function. (Only working from within Internet Explorer)

The Javascript function.

The function is very straight forward. I make use of the Silverlight.js function Silverlight.CreateObject. The function I created asks for three parameters, the hosting element (will contain the Silverlight control), the source (location of the xap file), and the initParams.

function CreateSilverlight(hostElement, source, initParams) { var pluginId = hostElement.id + "PluginId"; hostElement.innerHTML = Silverlight.createObject(source, null, pluginId, { width: "200", height: "50", background: "white", alt: "<!--Silverlight 2.not installed-->", version: "2.0.31005.0", autoUpgrade: true }, { onError: onSLError, onLoad: onSLLoad }, initParams, hostElement.id); }

Make it load from the window.load.

window.onload = function() { CreateSilverlight(silverlightControlHost, "ClientBin/MM.Silverlight.Experiments2.SUI.xap", "param1=value1,param2=value2"); }

The call from Silverlight.

I wanted to be able to see that the code was actually executed so I put a timestamp in. Calling Javascript from Silverlight is very easy, you can make use of either HtmlPage.Window.Eval or HtmlPage.Window.CreateInstance, I used HtmlPage.Window.Eval.

HtmlPage.Window.Eval(string.Format( @"CreateSilverlight(silverlightControlHost, 'ClientBin/MM.Silverlight.Experiments2.SUI.xap', 'currenttime={0},otherparam=othervalue');", DateTime.Now));

This is all, nothing more, the sad part I only got it working in Internet Explorer, but that might be because of some bad Javascript. I attached the full solution for download.

  • Gravatar Alex April 27th, 2010 at 10:58
    I know what's the problem
    you should change CreateSilverlight(silverlightControlHost ..) to CreateSilverlight(document.getElementById('silverlightControlHost')..)

    Alex.
  • Gravatar Ajas September 22nd, 2012 at 22:01
    Hi Cgcamilo .. This is right..Silverlight application run only on cienlt side (Calling services are different thing). To test applicatioon without services just publish on server and access from cienlt machine..after loading page just remove cienlt-server network connection. and u can see your application is running smoothly... Thanks --- Sachin Karche
  • Gravatar http://mommarazzischool.com/?p=6313 August 16th, 2014 at 03:13
    Car alternators have between 60 amps to 100 amps, so the max with a 100 amp alternator would be 12V X 100A = 1200 watts minus the 40 Watts = 1160 watts output. But you would need a chainsaw with about 2 HP or better output.
  • Gravatar nike lebron james viii August 28th, 2014 at 09:40
    15. Apply the finished meringue to the chilled pies.
  • Gravatar college jerseys cheap September 5th, 2014 at 03:03
    We have a wide range of good quality items throughout Football Outfits from which to choose shirt, customized cycling tops, custom made youth cycling tops, tailor made cycling tops, essential cycling tops, customise cycling tops
    college jerseys cheap http://www.jerseysbuynow.net/ncaa-discount-164.html
  • Gravatar Contact Us September 13th, 2014 at 01:59
    “Well, kawan-kawan. Sila beritahu si dia ni, siapa I?” Aira Syuhada mengarah.
  • Gravatar Nike Air Max Men(734) September 13th, 2014 at 02:01
    EMY ZUHANA merupakan seorang janda yang hartawan. Dia memegang status janda apabila arwah suaminya,Dato’ Isaac Mikhael meninggal dunia disebakan oleh penyakit jantung yang menyerangnya. Arwah meninggalkannya bersama tiga orang cahaya mata, dua lelaki dan seorang perempuan. Arwah juga seorang yang tegas dalam menjalankan tanggungjawabnya sebagai ketua keluarga dan juga CEO kepada Isaac & Zuhana SDN BHD. Didalam ketegasannya mendidik anak-anaknya,dia juga merupakan seorang bapa yang kuat bekerja bagi memastikan empayar perniagaannya terus kukuh bagi menjamin masa depan anak-anaknya.
  • Gravatar Men's Moncler Coats September 13th, 2014 at 10:21
    American, too, clearly states on its website that bags must adhere to the 22 x 14 x 9 inch rule. No one dimension must exceed those measurements in any way and the overall dimensions must not exceed 45 linear inches. But back in 2010, as this shows, only for travel within the U.S. are the specific 22 x 14 x 9 inch dimensions mentioned. For travel elsewhere, it just says "45 inches". So that's a change from what the website says today, where there appears to be no distinction between regions.
  • Gravatar Women's Moncler Jackets September 13th, 2014 at 10:23
    Follow columnist Nancy Armour on Twitter .
  • Gravatar Classic Short Botas 5825 UGGS September 21st, 2014 at 02:03
    To win that, he'll have to buck his consistent trend of faltering when the FedEx Cup playoffs roll around. He'll have to keep himself from thinking ahead to the Ryder Cup. Most of all, he'll have to stay awake. He took last week off to spend time with his wife, Kristin, and their daughter, Vale Esme, who was born last Monday.
  • Gravatar Nike Lunar Force 1 Homme September 23rd, 2014 at 23:09
    Separately, Syrian state-run TV said there was an explosion Monday near a school in the capital, Damascus.
  • Gravatar ysl outlet store online September 24th, 2014 at 11:46
    Quick response
  • Gravatar cleveland browns collar large October 15th, 2014 at 10:55
    Hey! This post could not be written any better!
    Reading this post reminds me of my old room mate! He always kept talking
    about this. I will forward this write-up to him.
    Fairly certain he will have a good read. Thanks for sharing!
  • Gravatar strength 21st century October 20th, 2014 at 03:57
    It's wonderful that you are getting thoughts from this article
    as well as from our argument made here.
  • Gravatar wsip testy November 19th, 2014 at 04:07
    As a standard, a professional translator is certified from the Associate of the Institute of Translation and Interpreting.

    The reason why I speak this to you is that you need to decide which branch of Portuguese to learn first.
    building going on but this is not large scale for Poland.
  • Gravatar Mariel January 25th, 2015 at 03:35
    Webmaster do you want unlimited content for your website?
    Type in google:
    Nysrisar's tool
  • Gravatar green botan arita 5 March 23rd, 2015 at 09:02
    What i do not understood is if truth be told how you are now not really a lot more smartly-liked than you may be now.
    You're very intelligent. You realize thus significantly with
    regards to this matter, made me individually imagine it from a lot of
    various angles. Its like men and women aren't fascinated except it's something to
    accomplish with Lady gaga! Your personal stuffs great. At
    all times maintain it up!
  • Gravatar CollinBGiacopelli July 12th, 2015 at 05:18
    I read this paragraph fully about the comparison of most recent and preceding technologies, it's remarkable article.
  • Gravatar Jolie Wiechert August 27th, 2015 at 21:39
    Refinancing at the actual interest levels would lower that monthly payment,
    but banks are unwilling to accomplish that whenever home values
    have dropped so significantly Jolie Wiechert the rates of interest of the small loans is going
    to be no less than 10 x lower.
  • Gravatar store September 6th, 2015 at 19:31
    Thank you for some other wonderful post. Where else could anybody get that kind of info in such an ideal way of writing?
    I have a presentation next week, and I'm on the look for such info.
  • Gravatar Gwyneth Sillman September 7th, 2015 at 23:23
    Give friends and family and family ever reason to believe that you
    just are sincere, capable and savvy Gwyneth Sillman many of such start-up loans feature minimal rates, rendering it easy to pay for the money back.
  • Usually I do not learn post on blogs, but I would
    like to say that this write-up very compelled me too take a look at and do so!
    Your writing taste has been amazed me. Thanks,
    quite nice post.
  • Gravatar charlotte bobcats racing jersey October 28th, 2015 at 05:10
    Spectators who don't comply are sold similar colored apparel make use of; whether they refuse, these are moved right out of the club place to another available seat. Nobody is dismissed of the arena. Wickett mentioned that very few people, under a handful, had tested the policy. The Chase Club holds about 1,000 people, additionally, the Lexus Lounge has 390 seats, Wickett said, representing 7.2 percent of your arenas capacity.
    charlotte bobcats racing jersey http://sportsmansgallery.com/bbs/Reyfk4IIJ/index.html
  • Lebron and Kyrie Irving know the dimensions and daunting task ahead in containing NBA MVP Stephen Curry inside Finals.James called Curry a worthy MVP during the time of the ceremony and elaborated about the shooting guard's skills with Game This is the Finals one week away Thursday, 9 p.m. ET, ABC.
    http://mti.gov.vn/jerseys/J5HCmRD0US/index.html http://mti.gov.vn/jerseys/J5HCmRD0US/index.html
  • Gravatar Cycling Shirts November 16th, 2015 at 13:24
    I have read several good stuff here. Certainly price bookmarking
    for revisiting. I wonder how so much effort you place to make the sort of excellent informative web site.
  • Gravatar linyuan March 14th, 2016 at 07:27
    linyuan0314
    http://www.policesunglasses.us.com
    http://www.cartieroutlet.us.com
    http://www.cazal.us.com
    http://www.chromehearts-outlet.com
    http://www.chanelsunglasses.in.netv edsede
    http://www.burberrysunglasses.us.com
    http://www.versacesunglasses.us.com
    http://www.cartierwatches.us.com
    http://www.chromeheartsoutlet.in.net
    http://www.pradasunglasses.us.com
    http://www.dior.us.com
    http://www.cartier.us.com
    http://www.guccisunglasses.us.com
    http://www.louisvuittonsunglasses.us.com
  • Gravatar HesterTGross June 1st, 2016 at 16:48
    When some one searches for his required thing, so he/she
    needs to become available that in detail, so that thing
    is maintained right here.
  • Gravatar YokoTAyola July 25th, 2016 at 16:59
    I'm unsure where you happen to be getting your info, but great
    topic. I must take some time learning more or understanding more.

    Many thanks for great info I wanted this information for my mission.
  • Gravatar DionJShown August 19th, 2016 at 17:50
    I found myself suggested this blog by my cousin. I'm unclear whether this
    post is written by him as no-one else know such detailed about my trouble.
    You happen to be wonderful! Thanks!
  • Gravatar LynnGAdderly September 13th, 2016 at 03:09
    I really do agree with each of the ideas you may have presented in your
    post. They're very convincing and might certainly work.
    Nonetheless, the posts are too brief for novices. May just you please lengthen them a
    little from next time? Many thanks for the post.
  • Gravatar air max 90 September 21st, 2016 at 06:41
    Have a heart and let me miss you I have great ambitions Not only do you still think you have been happy always happy forever health There is a love called care Have a feeling is sweet.
  • Gravatar adidas yeezy September 21st, 2016 at 06:41
    So have the layout of the differentiation, let the Nike + community platform "products and services access" positioning.Nike has on performance.
  • Gravatar new balance shoes September 21st, 2016 at 06:42
    This interesting advice signifies this much a person like me and especially to my office workers. With thanks; from each one of us.
  • Gravatar under armour shoes September 21st, 2016 at 06:42
    Thanks for every one of your work on this web page.Your informative tutorial implies much a person like me and further more to my colleagues.
  • Gravatar asics September 21st, 2016 at 06:42
    Led Britain is the world's largest business network, help like Niek Alofs such professionals find contacts within the enterprise, and through the network to contact candidates.
Gravatar