Javascript in htmlplaceholder to Silverlight

8 posts, 0 answers
  1. Reddy
    Reddy avatar
    2 posts
    Member since:
    Jun 2009

    Posted 22 Jul 2009 Link to this post

    How do I call Silverlight function from Javascript placed in htmlplace holder?
    I guess how do I get the reference to the silver light object which is hosting the html placeholder. The Javscript function that needs the reference of silverlight object is in the html hosted by the htmlplaceholder.


  2. Reddy
    Reddy avatar
    2 posts
    Member since:
    Jun 2009

    Posted 23 Jul 2009 Link to this post

    I do see the thread 'Calling Javascript functions from RadHtmlPlaceholder'.
    But, what I am looking for is reverse order. I need to call a function in silverlight control from the html hosted by the htmlplaceholder.

  3. DevCraft banner
  4. Bobi
    Admin
    Bobi avatar
    513 posts

    Posted 23 Jul 2009 Link to this post

    Hi Reddy,

    I am not sure if I understand you correctly, you ask:
    " I need to call a function in silverlight control from the html hosted by the htmlplaceholder."

    1. If you mean how to call in Silverlight a JavaScript function from the HTML hosted by the Htmlplaceholder then all you need to do is the following:

    in JavaScript
         
    function test() {
                    window.alert("This is a test function");
                }
    in Silverlight
              
               // Get the IFrame from the HtmlPresenter
                HtmlElement iframe = (HtmlElement)RadHtmlPlaceholder1.HtmlPresenter.Children[0];
                // Set an ID to the IFrame so that can be used later when calling the javascript
                iframe.SetAttribute("id", "myIFrame");
                // Code to be executed
                string code = "document.getElementById('myIFrame').contentWindow.test();";
                HtmlPage.Window.Eval(code);

    2.If you want to call managed C# code from JavaScript then take a look at the following articles:
    http://silverlight.net/quickstarts/htmlbridge1.aspx#html_bridge_overview
    http://msdn.microsoft.com/en-us/library/cc221414(VS.95).aspx

    Please l et us know if this does not answer your questions. 

    Sincerely yours,
    Boryana
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Srinivas
    Srinivas avatar
    48 posts
    Member since:
    May 2009

    Posted 08 Sep 2009 Link to this post

    I have a silverlight page which includes a RadHtmlPlaceholder.
    RadHtmlPlaceholder has a web page which has controls (e.g. buttons).
    When the button is clicked, I want to handle that event in Silverlight.

    This article points to Microsofts article

    http://silverlight.net/quickstarts/htmlbridge1.aspx#html_bridge_overview

     

    Which shows some sample code like..

    public Page()

    {

        InitializeComponent();

        HtmlDocument htmlDoc = HtmlPage.Document;

            ...

        // Add an event handler for the Convert button.

        HtmlElement  htmlEl = htmlDoc.GetElementById("Convert");

        htmlEl.AttachEvent("onclick", new EventHandler(this.OnConvertClicked));

    }

     

    void OnConvertClicked(object sender, HtmlEventArgs e)

    {

    }

    But this is for caller page not RadHtmlPlaceholder. Please show some samples for RadHtmlPlaceholder.

    I need help mainly on how to get the HtmlElement inside RadHtmlPlaceholder by name.

  6. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 09 Sep 2009 Link to this post

    Hello Srinivas,

    the article you are pointing to is working when the buttons are on the same page where the silverlight application is. Since you are using external page this will not be possible.

    If the page you are using is from the same domain you can still do it, but in a very different way.

    You will need first to handle the button clicks inside the page where you have registered the Silverlight application. Then you can simply call a method from the Silverlight application to get notified about the button click.

    All the best,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Valentin.Stoychev
    Admin
    Valentin.Stoychev avatar
    2198 posts

    Posted 09 Sep 2009 Link to this post

    Hi Srinivas,

    You can also check this thread for more info:
    http://www.telerik.com/community/forums/silverlight/htmlplaceholder/accessing-managed-code-from-htmlplaceholder-control.aspx

    Best wishes,
    Valentin.Stoychev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. kiran
    kiran avatar
    36 posts
    Member since:
    May 2008

    Posted 21 Mar 2011 Link to this post

    HI Telerik Team,

    I am using RadHtmlPlaceholder in my application. i wanted to show the currently installed silverlight plug-in version in that place holder. I am having a HTML page which will display the installed silverlight client version. But when i set the HTML place holder source as that HTML page code, it is not displaying the installed SL lient version.

    Could you please send me the code to display the installed SL plug-in version. Or provide some pointers on that.

    Thanks,
    Kiran
  9. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 24 Mar 2011 Link to this post

    Hello kiran,

    The html placeholder has no relation to the html page that you are displaying. What it does is to pass the source of the html page to an IFrame and display it. Are you saying that the html placeholder does not display the html page at all or just parts of it (where the SL plugin version is)?

    Kind regards,
    Alex Fidanov
    the Telerik team
Back to Top
DevCraft banner