This is a mirror of official site: http://jasper-net.blogspot.com/

Passing Values Between Pages in Silverlight 4

| Monday, October 10, 2011
In this post, we will look into some of the approaches available for passing values between Silverlight pages: a Silverlight page to a Silverlight page and an ASPX page to a Silverlight page. A typical approach in legacy web systems is using the QueryString, where parameters are passed as field–value pairs.
QueryString in Silverlight

In a real application scenario, suppose a Customer page appears when the user clicks on to see the details of a particular Customer. The customer ID/name will be used in the query string and can be passed to the CustomerDetail page. The CustomerDetail page will parse the URL and fetch the details from the data source based on the value from the query string.

Silverlight pages can access the query string from the NavigationContext property of the page (check my earlier post for more details). So in the above example, the CustomerDetail page can access it with one line of code: this.NavigationContext.QueryString["**QS Field Name**"].

// Executes when the user navigates to this page.
protected override void OnNavigatedTo(NavigationEventArgs e)
{
    lblQSValue.Content = this.NavigationContext.QueryString["PassQS"];
}

Passing Parameters from an ASPX Page to Silverlight Using InitParameters

Although QueryString is a way to pass values between pages, there are alternate ways of sending parameters to a Silverlight application, one of which is InitParam.

In an ASPX page, in the object tag where the XAP file gets loaded, we can add the following tag:

<param name=”InitParams” value=”PassVALA = IamA,PassVALB = 25″ />

<body>
<form id=”form1″ runat="”server”" style=”height:100%”>
<div id=”silverlightControlHost”>

   type=”application/x-silverlight-2″ width=”100%” height=”100%”>






  style=”text-decoration:none”>

  alt=”Get Microsoft Silverlight” style=”border-style:none”/>

<iframe id=”_sl_historyFrame”
  style=”visibility:hidden;height:0px;width:0px;border:0px”></iframe></div>
</form>
</body>

Read more: Codeproject
QR: Passing-Values-Between-Pages-in-Silverlight-4

Posted via email from Jasper-net

0 comments: