SilverlightIntrawebPart3


In the previous two parts of this series, we saw how to create a REST server using Intraweb and how to consume the data from Siverlight. In this part we're going to see how to update Intraweb controls using Silverlight.

To communicate with a page a Silverlight control is hosted in, we need to use Javascript (in either direction). To facilitate this task, from .NET we have access to a managed class that contains a representation of the DOM that the control is hosted in. Our Intraweb form should now contain our Silverlight control as well as some Intraweb Controls like a TIWEdit called editDate. For now we can ignore the other controls.


Our Silverlight control also has some new controls, in particular a date picker and a new button

The idea is to send the contents of the date picker to the Intraweb edit control when the user hits the To Intraweb button. To do so, as mentioned, we use the DOM class available in .NET, as shown in the figure below:

    private void SendInfo(object sender, RoutedEventArgs e) {
      var element = HtmlPage.Document.GetElementById("EDITDATE");
      if (element != null) {
        element.SetAttribute("value", datePicker.SelectedDate.ToString());
      } 
    }

As you can see, it's quite simple. We obtain a reference to our control and then set the value attribute. If we now select a date and hit the button, our editDate control will be updated in Intraweb.

In the next section we'll see how to talk back to Silverlight from Intraweb.