How can I get a variable in a Silverlight 3 control from my ASP.NET code?

I play with Silverlight 3 in the moment. I'm trying to get the current user id on the Silverlight 3 page. I did a bit of research, and initParams seems to be the right way. The problem is that they seem to have used the asp: Silverlight control, and that was in SL3. I am stuck trying to get a variable in the initParams list, assuming this is the right way.

I started with a new Silverlight 3 application called "MyFirstSilverlightApp". I added a code page for "MyFirstSilverlightAppTestPage.aspx" to allow me to make any smart bits.

I managed to hardcode the initParam by adding this to the object's restriction parameters:

    <param name="initParams" value="userID=id42" />

In App.xaml.cs, I added the following to Application_Startup:

    string userID = e.InitParams["userID"];

and I passed this to my page in a parameter in the constructor, and then used it in the control. It all works.

What I can’t solve is how to get the value from the variable I created in the code in the definition of the value of the parameter name. Any help would be greatly appreciated.

+3
source share
2 answers

One quick dirty approach would be to use <% %>in a parameter: -

<param name="intiParams" value="userID=<%=myUserID%>" />

My preferred solution is to create my own Silverlight Web Control, which can display the object tag and its contents in accordance with my application.

+2
source

.

- .

For Each item As KeyValuePair(Of String, String) In e.InitParams
    Resources.Add(item.Key, item.Value)
Next
0

Source: https://habr.com/ru/post/1718174/


All Articles