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

Passing Values Between Pages in Silverlight 4

| Monday, March 7, 2011
 In this post we will look into some of the approaches available for Passing Values between Silverlight pages SL To SL page and ASPX To SL page .Typical approach of legacy web system is Query String , where parameters are passed as Field –Value Pair.

Query String In Silverlight

In real application scenario suppose a Customer page when the User Clicks on Detail  of particular Customer.The customer id / Name will be used in query string and can be passed to the CustomerDetail page.The CustomerDetail page will parse the URL and fetch the details from data source based on the value from query string.

The Silverlight pages can access the query string from NavigationContext property of page (Check my earlier post for more detail ).So as of the above example the CustomerDetail page can access it with following one liner 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 Aspx Page to Silverlight by InitParameters

Although Query String is a way to pass the values between pages we can use alternate way of sending parameters to Silverlight application that is InitParam.

From Aspx page in Object Tag where the xap file is getting loaded we can add following tag.

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

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

</div>
</form>
</body>

Read more: C# Corner

Posted via email from Jasper-net

0 comments: