This is a mirror of official site: http://jasper-net.blogspot.com/

Silverlight JavaScript Integration - Part 1

| Sunday, July 17, 2011
Introduction

Silverlight is a browser-based plug-in. This plug-in was designed to be integrated with web pages.

Document Object Model (DOM) will allow web applications and scripts to dynamically access and update the content and schema of documents.

Using the Code
    Access HTML elements and modify its properties:

    div id="headerDiv" style="width:100%; height:20%; background-color:Red"

    private void btnAccessHtmlElements_Click(object sender, RoutedEventArgs e)
            {
                System.Windows.Browser.HtmlDocument doc =
                System.Windows.Browser.HtmlPage.Document;
                System.Windows.Browser.HtmlElement headerDiv =
                doc.GetElementById("headerDiv");
                headerDiv.SetStyleAttribute("background-color", "green");
            }

    Access the value of query string.

    Suppose the web page opened with the following link:

        http://localhost:7410/SilverlightDomInteractionTestPage.aspx?employeeID=600

    private void btnAccessQueryStrings_Click(object sender, RoutedEventArgs e)
    {
        System.Windows.Browser.HtmlDocument doc=
            System.Windows.Browser.HtmlPage.Document;
        int empID = int.Parse(doc.QueryString["employeeID"]);
        MessageBox.Show(empID.ToString());//Results 600
    }

    Access all values of query strings.

    Suppose the web page opened with the following link:

        http://localhost:7410/SilverlightDomInteractionTestPage.aspx?employeeID=600&sallaryLessthan=2000

    private void btnAccessAllQueryStrings_Click(object sender, RoutedEventArgs e)
    {
        Dictionary<string, string> QueryStrings = new Dictionary<string, string>();
        System.Windows.Browser.HtmlWindow win =
                    System.Windows.Browser.HtmlPage.Window;
        System.Windows.Browser.HtmlDocument doc =
                    System.Windows.Browser.HtmlPage.Document;
        foreach (string key in doc.QueryString.Keys)
        {
            QueryStrings.Add(key, doc.QueryString[key]);
        }
        MessageBox.Show(QueryStrings.Count.ToString());//Results 2


Read more: Codeproject
QR: SilverlightJS_Integration.aspx

Posted via email from Jasper-net

0 comments: