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 SilverlightIn 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 InitParametersAlthough 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”>
<iframe id=”_sl_historyFrame”
style=”visibility:hidden;height:0px;width:0px;border:0px”></iframe></div>
</form>
</body>Read more: Codeproject
QR:
QueryString in SilverlightIn 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 InitParametersAlthough 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”>
<iframe id=”_sl_historyFrame”
style=”visibility:hidden;height:0px;width:0px;border:0px”></iframe></div>
</form>
</body>Read more: Codeproject
QR:
0 comments:
Post a Comment