Let's walk through the process. I'm going to assume that you've got a machine already set up with Visual Studio 2008 Beta 1 (previously codenamed "Orcas") and the Silverlight project template add-on.
<p>Input: <input type="text" id="input" />
<input type="button" id="parseDate" value="Parse >>" />
<input type="text" id="output" size="50" />
<textarea id="browserCaps" cols="100" rows="6"></textarea>
<h1>Adding Style to the Page</h1>
<input type="button" id="addStyle" value="Style Me!" />
Let's also add a declaration for the System.Windows.Browser namespace:
hdoc = HtmlPage.Document;
string browserCaps =
"Name: " + HtmlPage.BrowserInformation.Name + "\n" +
"Platform: " + HtmlPage.BrowserInformation.Platform + "\n" +
"User Agent: " + HtmlPage.BrowserInformation.UserAgent + "\n" +
"Cookies Enabled: " + HtmlPage.BrowserInformation.CookiesEnabled;
public void OnParseDateButtonClick(object sender, HtmlEventArgs args)
string input = hdoc.GetElementByID("input").GetProperty<string>("value");
DateTime inputAsDate = DateTime.Parse(input);
output = inputAsDate.ToString("R"); // RFC 1123 string
catch (FormatException e)
output = "Error: " + e.Message;
public void OnAddStyleButtonClick(object sender, HtmlEventArgs args)
HtmlElementCollection hec = hdoc.GetElementsByTagName("h1");
foreach (HtmlElement h1 in hec)
If you've got the Silverlight 1.1 Alpha on your machine, you can browse straight to the finished page to see it in action. I've also made the source code available for the above walkthrough, in case you aren't able to complete the steps above for whatever reason.
Have fun with this!
Silverlight Cream for June 13, 2007
You've been kicked (a good thing) - Trackback from DotNetKicks.com
It is really a good approach to get interaction with html controls. I really admire your efforts and work.
Silverlight will create huge gap for the compitaters.
Very cool, thanks for the little tutorial.
I'm impressed that it works in both IE7 and Firefox, too. I think that's one scourge of ClickOnce is that it doesn't work in other browsers (although I hear Orcas fixes this...)
Wewwww!!! this is so damn cool..
Very interesting C# article!
Too bad this doesn't work in VS 2005. Argh.
You might want to update the page so that it operates with the 1.1 Alpha refresh.