Page view counter

Reach Out And Touch HTML

I've posted a new video that shows how Silverlight 1.1 lets you create custom controls that can reach out to the HTML host page. In the example, we not only touch HTML controls, but we also respond to events (a button press) on an HTML control. The enabling technology is in the name space System.Windows.Browser.

The work turns on creating HtmlElement objects as member variables of your class.  These objects have an AttachEvent method that takes the name of the event and an event handler as arguments, as shown in this snippet:


private HtmlElement newMessageTextBox;
private HtmlElement updateButton;
private HtmlElement fontSizeTextBox;

public void Page_Loaded(object o, EventArgs e)
{
    InitializeComponent();

    HtmlDocument document = HtmlPage.Document;
    newMessageTextBox = document.GetElementByID("messageInput");
    updateButton = document.GetElementByID("update");
    updateButton.AttachEvent(
        "onclick", 
        new EventHandler(this.updateButton_Click)
    );
}

The HtmlPage is able to get the current (HTML) Document and from that we can get the (HTML) TextBox that was placed on the Document. With the document in hand, we can get the button, declared in TestPage.html as

<input id="update" type="button" value="Update" />

With a reference to the button, we can add the event handler that we can then implement in managed code. Very slick and reverses the visibility that was required in 1.0 (in which the HTML page was reaching into the Silverlight control).

 

Published Thursday, October 25, 2007 12:53 PM by jesseliberty

Comments

# Reach Out And Touch HTML - Jesse Liberty - Silverlight Geek

Pingback from  Reach Out And Touch HTML - Jesse Liberty - Silverlight Geek

Thursday, October 25, 2007 2:02 PM by Reach Out And Touch HTML - Jesse Liberty - Silverlight Geek

# re: Reach Out And Touch HTML

This video is very educational. Great job on the video!

..Ben

Thursday, October 25, 2007 2:17 PM by BenHayat

# re: Reach Out And Touch HTML

Jesse, I have a question on your other video (XML vs C#). When you define objects declaratively in XAML (i.e. rectangular) and then when you compile/build the project, does the XAML file gets converted into C# and becomes part of the DLL? Or will the contents of XAML file get loaded into SL engine at runtime and then objects get created from reading raw XAML file?

I see that the XAML file has a "Build Action" that can bet set as "Embedded Resource", but what would that do for us?

My question is really in two folds: a) Isn't XAML file slower than if we created objects in C#?

b) How can we protect the contents of XAML file?

Thanks!

..Ben

Thursday, October 25, 2007 2:45 PM by BenHayat

# Silverlight Cream for October 25, 2007 -- #112

Silverlight Cream for October 25, 2007 -- #112

Thursday, October 25, 2007 6:31 PM by WynApse

# Reach Out And Touch HTML

I&#39;ve posted a new video that shows how Silverlight 1.1 lets you create custom controls that can reach

Friday, October 26, 2007 1:03 AM by Test

# Izindaba #15

Time for another weekly round-up of developer news that focuses on .NET, agile and general development

Friday, October 26, 2007 1:29 AM by From the software development trenches

# html &raquo; Reach Out And Touch HTML

Pingback from  html &raquo; Reach Out And Touch HTML

Saturday, October 27, 2007 4:20 PM by html » Reach Out And Touch HTML

# re: Reach Out And Touch HTML

Ben,

If you create a Silverlight Control (using the class library option) and you choose Embedded resource, then you get a dll. As for "protecting" your XAML, if you mean protecting the Intellectual Property, I think you are on as difficult ground as always with .NET but I'll have to look into it further. Meanwhile I suggest something like this:

This message is copyright, trademark, contains trade secrets, trussreppers will be persecuted, company confidential, void where prohibited, no warranty express or implied, contents are hot, your mileage may vary, I never borrowed it, it was broken when you leant it to me and I returned it in perfect condition. Don't Panic. Answer the question or we'll gag you. What question? Gag him.

The opiinons expressed are not mine.

Tuesday, October 30, 2007 11:54 AM by jesseliberty

# SilverSpud &raquo; Blog Archive &raquo; My Favorite Blogs - Last 5 Posts as of 03 Nov 2007

Pingback from  SilverSpud  &raquo; Blog Archive   &raquo; My Favorite Blogs - Last 5 Posts as of 03 Nov 2007

# re: Reach Out And Touch HTML

Jesse,

I'm trying to run your code from this example and all of the document.GetElementByID(...) are returning null.  I am getting a message from IE that it has blocked content which I haven't seen before with silverlight... when I say to allow the content the page_loaded event fires but I still don't get any references to the HtmlElements defined.

Thanks for your help.

Tuesday, November 06, 2007 11:58 AM by BigTundra

# video &raquo; Reach Out And Touch HTML

Pingback from  video &raquo; Reach Out And Touch HTML

Saturday, November 24, 2007 1:33 PM by video » Reach Out And Touch HTML

# http://silverlight.net/blogs/jesseliberty/archive/2007/10/25/reach-out-and-touch-html.aspx