This is a migrated thread and some comments may be shown as answers.

Javascript in htmlplaceholder to Silverlight

7 Answers 142 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Reddy
Top achievements
Rank 1
Reddy asked on 22 Jul 2009, 05:08 PM
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.


7 Answers, 1 is accepted

Sort by
0
Reddy
Top achievements
Rank 1
answered on 23 Jul 2009, 10:01 AM
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.

0
Bobi
Telerik team
answered on 23 Jul 2009, 02:46 PM
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
0
Srinivas
Top achievements
Rank 1
answered on 09 Sep 2009, 12:18 AM

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.

0
Valentin.Stoychev
Telerik team
answered on 09 Sep 2009, 07:15 AM
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.
0
Valentin.Stoychev
Telerik team
answered on 09 Sep 2009, 08:26 AM
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.
0
kiran
Top achievements
Rank 1
answered on 21 Mar 2011, 07:55 PM
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
0
Alex Fidanov
Telerik team
answered on 24 Mar 2011, 04:45 PM
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
Tags
HTMLPlaceHolder
Asked by
Reddy
Top achievements
Rank 1
Answers by
Reddy
Top achievements
Rank 1
Bobi
Telerik team
Srinivas
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
kiran
Top achievements
Rank 1
Alex Fidanov
Telerik team
Share this question
or