I have a page that displays a list of users. each user has an ID and a HyperlinkButton to watch more details about the user.
When pressing the HyperlinkButton, I would like to navigate to another page (called UserDetails) and somehow read the ID of the user that was pressed.
How can I do that?
Thanks, Ronny
I Found a nice solution, but I would like to hear something that is more elegant.
Within the UriMapper section I have added another UriMapping:
<uriMapper:UriMapping Uri="/UserDetails/{UserId}" MappedUri=/Views/UserDetails.xaml"/>
By doing so, all navigation in the format of "/UserDetails/XXX will be navigated to same page, UserDetails.xaml.
So now my HyperlinkButton is generated with a NavigateUri with the needed format:
NavigateUri="/UserDetails/1234"
Now, on the UserDetails.xaml page, in the OnNavigatedTo method, I can parse the Uri parameter (e.Uri) and load the User details accordingly.
you can use NavigationContext to get data from query string.. try this:
<HyperlinkButton NavigateUri="/UserDetails?userId=123" />
and than in the navigated page something like this
string customerId = this.NavigationContext.QueryString["customerid"];
What about put ID
in query string like so.
<HyperlinkButton
x:Name="btn" /**other properties**/
NavigateUri="http://www.yoururl.com/details.aspx?ID=1234">
</HyperlinkButton>
in Details.aspx
you can put ID in initParams
property of silverlight object
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="initParams" value='<%= GetID() %>' />
</object>
in Details.aspx.cs
, code behind of Details.aspx
, you fill the initParams like so
public string GetID(){
return string.Format("ID={0}", Request.QueryString[0]);
}
then, you can read the ID from your silverlight application startup
private void Application_Startup(object sender, StartupEventArgs e)
{
int ID = Convert.ToInt32(e.InitParams["ID"]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With