Startsidan  ▸  Texter  ▸  Teknikblogg

Anders Hesselbom

Programmerare, skeptiker, sekulärhumanist, antirasist.
Författare till bok om C64 och senbliven lantis.
Röstar pirat.

Getting started with Silverlight in an existing web application

2010-09-25

To get things started, I will show how to enhance a web application with a Silverlight object, and how to pass parameters to that object. To be able to follow, make sure that you have the Silverlight runtime installed. Also, you must have an existing ASP.NET Web Application loaded in Visual Studio 2010. If you’re using Visual Studio 2008, there is an Silverlight addon available for download from Microsoft.

Adding a Silverlight object and passing data to it
I want to have a Silverlight object on a sub page, so I add a new ASPX page to my web application called sl.aspx. Also, I create a link to sl.aspx from my default page. I want my Silverlight object to accept a QueryString argument, so I pass one in my link:

<a href="sl.aspx?param=hello">Click here!</a>

1. Add a new Silverlight project to your solution. I use the name MySL for mine. Default, a test page is added. I unchecked the option to make the test page my start page.

2. The test page is a good help to copy the HTML code that is required to show the object from. The two JavaScript blocks goes in the head section and the OBJECT tag goes where you want your Silverlight object. Grab the DIV tag that contains the OBJECT tag and the IFRAME tag.

Now you’re done with adding the object. If you test your application, and click on your link, your (empty) Silverlight object.

3. I want to show the QueryString parameter in a textbox, so I add one to my Silverlight object (TextBox1). This is the code to grab the QueryString parameter and putting it in the textbox:

Private Sub MainPage_Loaded(ByVal sender As Object, _
ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
   TextBox1.Text = _
   System.Windows.Browser.HtmlPage.Document.QueryString("param")
End Sub

The result of course, is the word “hello” in the textbox.

Categories: VB.NET, Visual Studio 10

Tags: Silverlight

Leave a Reply

Your email address will not be published. Required fields are marked *



En kopp kaffe!

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Bjud på en kopp kaffe!

Om...

Kontaktuppgifter, med mera, finns här.

Följ mig

Twitter Instagram
GitHub RSS

Public Service

Folkbildning om public service.

Hem   |   linktr.ee/hesselbom   |   winsoft.se   |   80tal.se   |   Filmtips