views:

258

answers:

2

I'm brand new to learning Silverlight/XAML/C#.

I'm using an ASP.NET function to pass a string parameter to a Silverlight App. Currently I'm using the following code to simply verify that it works when the Silverlight App is loaded:

<Grid x:Name="LayoutRoot">
    <StackPanel>
        <TextBlock x:Name="txtIP" />
    </StackPanel>
</Grid>

How do I set up an element that's "behind the scenes" that doesn't necessarily display in the XAML? I thought about simply hiding the TextBlock, but I imagine there's a better way.

A: 

You can pass parameters to a Silverlight application using the initParams option in the plugin. Load that with some ASPNET code and you can dynamically set it at load time.

Tim Heuer
Tim, you are ubiquitous :-). I like the idea of using initParams, but I'm having a hard time figuring out how to pass my javascript variable on the ASP.NET page into the HTML. Since the ASP:Silverlight control was removed from the Silverlight 3 SDK, I'm not exactly sure what to do. Am I going to have to write the whole line in Javascript? Ideas?
Ben McCormack
Ok, that took way too long, but I figured out I could use the <% %> feature in ASP.Net. Like I said, I'm new to this. However, using the initParams options is much nicer than what I had before.
Ben McCormack
A: 

For further information on how to pass initParams into a Silverlight, check out Tim's video demonstration on InitParams here: Using Startup Parameters with Silverlight.

Also, check out my blog post where I cover several of the details in Tim's video and show what to do with the data once it's in the Silverlight App: Pass the IP Address of a User to Silverlight as a Parameter.

Ben McCormack