I'm playing with Silverlight 3 at the mo. I'm trying to get the current user ID into the Silverlight 3 page. I've done a bit of research and initParams seems to be the right way to go. Trouble is, they seemed to use the asp:Silverlight control and that's gone in SL3. I'm stuck trying to get a variable into the initParams list, assuming this is the right way to go.
I've started with a new Silverlight 3 application called "MyFirstSilverlightApp". I've added a code-behind page to the "MyFirstSilverlightAppTestPage.aspx" to allow me to do any clever bits.
I've managed to hard-code an initParam by adding this to the params of the object defenition:
<param name="initParams" value="userID=id42" />
In App.xaml.cs, I've added the following to Application_Startup:
string userID = e.InitParams["userID"];
and I've passed that into my page in a parameter in the constructor and then used that in a control. That all works.
What I can't work out is how to get the value from the variable I created in the code-behind into the param name value definition. Any help would be gratefully received.
One quick a dirty approach would be to use <% %> in the param:-
<param name="intiParams" value="userID=<%=myUserID%>" />
My prefered solution is to create my own Silverlight Web Control that can render the object tag and its contents in manner taylored to my application.
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