SilverlightShow: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? Comments http://www.silverlightshow.net/ Silverlight articles, Silverlight tutorials, Silverlight videos, Silverlight samples SilverlightShow.net http://www.rssboard.org/rss-specification Argotic Syndication Framework 2008.0.2.0, http://www.codeplex.com/Argotic en-US estoychev@completit.com (Emil Stoychev) Re: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? <div>You can use the code to access InitParams in your application </div> <p><strong>Application.Current.Host.InitParams["KeyName"]</strong></p> http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment6255 shadiabuhilal http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Fri, 03 Jun 2011 18:01:14 GMT RE: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? <p>If those params changed, how can I know it, from the App.xaml.cs</p> <p></p> http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment5448 Yissel http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Mon, 07 Feb 2011 22:42:14 GMT RE: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? <p><br /> </p> <ul> <li><strong>Great</strong> <div class="reCodeBlock" style="border:1px solid #7f9db9;width: 345px; height: 34px; overflow-y: auto;"> <div style="background-color: #ffffff;"><code style="color: #5c5c5c; float: left; width: 3em; padding-right: 0.3em; text-align: right; display: block;">1.</code><span style="margin-left: 0px !important;"><code style="color: #000000;">thanks</code></span></div> </div> </li> </ul> <p><br /> </p> http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment5428 Ajay http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Fri, 04 Feb 2011 10:23:42 GMT RE: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? Great !.Thanks http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment3045 Muhammad Talha http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Mon, 08 Feb 2010 11:07:06 GMT RE: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? Is it possible to set the initparameters via javascript? http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment1207 ange http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Wed, 18 Mar 2009 14:57:38 GMT RE: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? <p>The Silverlight itself can access the Url and get the QueryString, so you don't have to bother with passing it tio the HTML that invokes your Silverlight application. Using the HtmlPage class you are able to access the DOM and the url of the current page:</p> <div> <div style="border-style: none; padding: 0px; overflow: visible; background-color: rgb(244, 244, 244); font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%;"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%; background-color: white;"><span style="color: rgb(0, 0, 255);">string</span> queryParam = HtmlPage.Document.QueryString[<Key>];</pre> </div> </div> <p>For example you can do the following thing: In the App.xaml.cs add the following code in the Application_Startup handler:</p> <div> <div style="border-style: none; padding: 0px; overflow: visible; background-color: rgb(244, 244, 244); font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%;"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%; background-color: white;"><span style="color: rgb(0, 0, 255);">private</span> <span style="color: rgb(0, 0, 255);">void</span> Application_Startup( <span style="color: rgb(0, 0, 255);">object</span> sender, StartupEventArgs e )</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; background-color: rgb(244, 244, 244); font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%;"> {</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%; background-color: white;"> <span style="color: rgb(0, 0, 255);">this</span>.RootVisual = <span style="color: rgb(0, 0, 255);">new</span> Page();</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; background-color: rgb(244, 244, 244); font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%;"> <span style="color: rgb(0, 0, 255);">string</span> queryParam = HtmlPage.Document.QueryString[<span style="color: rgb(0, 96, 128);">"key"</span>];</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%; background-color: white;"> <span style="color: rgb(0, 0, 255);">this</span>.Resources.Add( <ResourceKey>, queryParam );</pre> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; background-color: rgb(244, 244, 244); font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%;"> }</pre> </div> </div> <p>This way you can access the parameter through the application resources, which means it will be easyly accessible from both the Xaml and the Codebehind. The synthax for accessing the resource is:</p> <p><strong>XAML</strong></p> <div> <div style="border-style: none; padding: 0px; overflow: visible; background-color: rgb(244, 244, 244); font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%;"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%; background-color: white;"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(128, 0, 0);">silverlightControl</span> <span style="color: rgb(255, 0, 0);">Property</span>={<span style="color: rgb(255, 0, 0);">StaticResource</span> <span style="color: rgb(255, 0, 0);">ResourceKey</span>} <span style="color: rgb(0, 0, 255);">/></span></pre> </div> </div> <p><strong>C#</strong></p> <div> <div style="border-style: none; padding: 0px; overflow: visible; background-color: rgb(244, 244, 244); font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%;"> <pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-family: Consolas,'Courier New',Courier,Monospace; font-size: 8pt; line-height: 12pt; color: black; width: 100%; background-color: white;"><span style="color: rgb(0, 0, 255);">object</span> parameter = ( ( App )Application.Current).Resources[ <ResourceKey> ];</pre> </div> </div> <p>That's it! ;)</p> http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment1002 Enrai http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Mon, 02 Feb 2009 06:37:53 GMT RE: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? <p> What I need to do is eactly what you have shown, thanks.  But I must also set the parameter from the code-behind of the page that is hosting the Silverlight control.  You have them set in the HTML that invokes the control: this will not work in my case, because the parameter is not known until run time.  I am passing it into the page on the Query String.  I can then retrieve the parameter, that is no problem.  But I can't figure out how to set it into the html that invokes the Silverlight control.  Can you show me how this is done? Thanks!</p> http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment996 Russ Blake http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Sun, 01 Feb 2009 05:03:43 GMT RE: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? <p>And what if you're using Silverlight in the ASP.NET MVC framework?</p> <p>I'd like to pass in parameters from data in my model, but I don't want to use the code behind to set them, because in the RC1 of MVC ,ASPX code behind files will be no more !</p> <p>If you try to pass in parameters in the ASPX file you get the following error:</p> <p> "Server tags cannot contain <% ... %> constructs"</p> <p> </p> http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment898 Alan http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Mon, 12 Jan 2009 12:04:46 GMT RE: Tip: How to pass initialize parameters to Silverlight application using ASP.NET 3.5 Silverlight control? <p>But how would I read values from a database control and pass them into the silverlight InitParams?</p> http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx#comment805 PaulHemmings http://www.silverlightshow.net/items/How-to-pass-initialize-parameters-to-Silverlight-application-using-ASP.NET-3.5-Silverlight-control.aspx Sun, 07 Dec 2008 21:03:28 GMT