I have an asp.net page (called trackDetails.aspx) hosted in master page. TrackDetails gets passed a query string to identify which track the page will show the details for ('TrackDetails.aspx?TrackID=<%# Eval("TrackID") %>').
On the TrackDetails page I am going to host a silverlight mp3 player which consists of a media element some buttons and a listbox whose data is bound to a query based on the TrackID.
When I hard code the initparams of the silverlight object everything works fine, i.e.
The pertinent lines of code are in bold. basically I got a reference to HTML page and then set the value of a string to the DocumentUri.Query value. then parsed the trackID from the query strings. I used the delimeter of '=' because the querystring of the
pages was "EditTracks.aspx?TrackID=<%# Eval("TrackID") %>" therefore all I wanted was the data after the = sign.
I hope this can help someone else and save them the time it took me to dig out the methods to accomplish it
northernwriter
0 Points
8 Posts
pass dynamic data from asp.net page to silverlight app?
Feb 22, 2011 03:23 PM | LINK
I have an asp.net page (called trackDetails.aspx) hosted in master page. TrackDetails gets passed a query string to identify which track the page will show the details for ('TrackDetails.aspx?TrackID=<%# Eval("TrackID") %>').
On the TrackDetails page I am going to host a silverlight mp3 player which consists of a media element some buttons and a listbox whose data is bound to a query based on the TrackID.
When I hard code the initparams of the silverlight object everything works fine, i.e.
<param name="initParams" value="Control=S360P_CS_SLB_v2.mp3Player, ID=2" />
What I need to be able to do is to dynamically assign the "ID=(TrackID variable)" portion of the parameter.
I have read that this can only be done by using javascript but I don't know how to write the java script to do this. Can anyone help?
Thanks
Les Williams
javascript initParams
alt_fo
Contributor
6414 Points
1313 Posts
Re: pass dynamic data from asp.net page to silverlight app?
Feb 22, 2011 05:01 PM | LINK
http://www.dotnetcurry.com/ShowArticle.aspx?ID=170&AspxAutoDetectCookieSupport=1
check the above link.
you can even think of WCF service duplex when u update in asp.net can callback to silverlight.
you can use querystring
Senthamil.
Please Mark Answered, If my solution solves your problem.
northernwriter
0 Points
8 Posts
Re: pass dynamic data from asp.net page to silverlight app?
Feb 22, 2011 05:46 PM | LINK
The link you sent me is for older versions of silveright. I am using silverlight 4 and asp.net 4 there isn't an asp:silverlight control available.
thanks though
northernwriter
0 Points
8 Posts
Re: pass dynamic data from asp.net page to silverlight app?
Feb 23, 2011 02:53 PM | LINK
I figured out how to do it!
So for anyone else interested here is the answer:
1: In my silverlight control for the mp3 player I added this code:
using System.Windows.Browser;
public mp3Player()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(mp3Player_Loaded);
}
void mp3Player_Loaded(object sender, RoutedEventArgs e)
{
HtmlDocument doc = HtmlPage.Document;
int trackID;
string QueryStrings = doc.DocumentUri.Query.ToString();
char[] delimChar = {'='};
string[] words = QueryStrings.Split(delimChar);
if (words[1] != null)
{
trackID = Convert.ToInt32(words[1]);
}
listBoxDemos.ItemsSource = _context.TrackDetails;
_context.Load(_context.GetTrackDetailsByTrackIDQuery(trackID));
}
The pertinent lines of code are in bold. basically I got a reference to HTML page and then set the value of a string to the DocumentUri.Query value. then parsed the trackID from the query strings. I used the delimeter of '=' because the querystring of the pages was "EditTracks.aspx?TrackID=<%# Eval("TrackID") %>" therefore all I wanted was the data after the = sign.
I hope this can help someone else and save them the time it took me to dig out the methods to accomplish it
alt_fo
Contributor
6414 Points
1313 Posts
Re: pass dynamic data from asp.net page to silverlight app?
Feb 23, 2011 04:13 PM | LINK
You have used one of my suggested method anyway, the querystring
Senthamil.
Please Mark Answered, If my solution solves your problem.
northernwriter
0 Points
8 Posts
Re: pass dynamic data from asp.net page to silverlight app?
Feb 23, 2011 09:14 PM | LINK
Yes I did thanks for the tip