Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight passing parameters between pages using HyperlinkButton

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

like image 949
Ronny Avatar asked Nov 07 '09 09:11

Ronny


3 Answers

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.

like image 66
Ronny Avatar answered Nov 06 '22 21:11

Ronny


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"];
like image 41
pori Avatar answered Nov 06 '22 21:11

pori


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"]);
    }
like image 21
Anwar Chandra Avatar answered Nov 06 '22 23:11

Anwar Chandra