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

Creating new html elements

9 Answers 133 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Telemetry
Top achievements
Rank 1
Telemetry asked on 27 Jul 2010, 01:59 PM
Hi, I need to be able to create new html elements in the radhtml placeholder. I can do this with C# by using HtmlPage.Document.CreateElement("div"). Is there a way to do this in the html placeholder control? Including OOB? Thanks!

9 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 30 Jul 2010, 03:13 PM
Hi James,

The HtmlPlaceholder displays html pages / content in an IFrame. You can access this IFrame's content like so:

HtmlElement iframe = (HtmlElement)myHtmlPlaceHolder.HtmlPresenter.Children[0];
HtmlWindow contentWindow = iframe.GetProperty("contentWindow") as HtmlWindow;
HtmlDocument document = contentWindow.GetProperty("document") as HtmlDocument;
Then you can either look for a specific element on the page, like so:
HtmlElement content = document.GetElementById("content"); or you can add new element in the HtmlDocument document.

I hope this information helps. Let us know if we can further assist you.

All the best,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Telemetry
Top achievements
Rank 1
answered on 30 Jul 2010, 04:40 PM
Thanks so much for the response. This looks like its just what I need. The only problem I'm having so far is that iframe.GetProperty("contentWindow") is returning null. Is that the correct property name?
0
Telemetry
Top achievements
Rank 1
answered on 30 Jul 2010, 05:01 PM
For whatever reason it looks like whats being passed back from :

this.iframe = (HtmlElement)this.HtmlPresenter.Children[0];

is 'div' instead of an iframe.
0
Accepted
Tina Stancheva
Telerik team
answered on 30 Jul 2010, 05:04 PM
Hi James,

Yes this is the correct property. However, if you are trying to access it before the content of the RadHtmlPlaceHolder is loaded, it will return null indeed. Therefore I'd suggest you to move your logic into the RadHtmlPlaceHolder UrlLoaded() event handler.

I also attached a sample project illustrating a possible approach towards your scenario. Take a look at it and let me know if it helps.

Kind regards,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Telemetry
Top achievements
Rank 1
answered on 30 Jul 2010, 06:04 PM
Thanks Tina this worked perfectly. I didn't notice the UrlLoaded event. Another problem I ran into is that I have some silverlight functions that are exposed to javascript. I've been calling them by using 'document.getElementById('SilverlightControl').Content' and then calling the function. If this is running out of browser, is there a way to call the Silverlight app from the htmlplaceholders javascript? Thanks!
0
Kiril Stanoev
Telerik team
answered on 04 Aug 2010, 04:55 PM
Hello James,

Unfortunately this scenario is not possible. We did some extensive testing but we were unable to workaround it. The reason is as you might expect the OutOfBrowser functionality. However, if you manage to come up with a solution, we'd be more than glad if you share it with us.

Best wishes,
Kiril Stanoev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Shaikh Ahmad
Top achievements
Rank 1
answered on 26 Aug 2010, 08:02 PM
Hi James,

I've came across this type of problem and there is a few things that i've tried. I'm not really sure is this what you are looking for but this is how i interact silverlight htmlplaceholder.
Hope this helps.

public class HtmlEditor : Telerik.Windows.Controls.RadHtmlPlaceholder
    {
        public HtmlEditor()
        {
            this.Loaded += new RoutedEventHandler(HtmlEditor_Loaded);
        }
  
        void HtmlEditor_Loaded(object sender, RoutedEventArgs e)
        {
            string url = "http://localhost:33333/Editor.aspx";
            this.SourceUrl = new Uri(url);
        }
  
        public string HtmlContent
        {
            get
            {
                string guid = Guid.NewGuid().ToString().Replace("-", "");
                HtmlElement iframe = (HtmlElement)this.HtmlPresenter.Children[0];
                // Set an ID to the IFrame so that can be used later when calling the javascript   
                iframe.SetAttribute("id", guid);
                string code = "document.getElementById('" + guid + "').contentWindow.GetHtml();";
                string html = (string)HtmlPage.Window.Eval(code);
                return html;
            }
            set
            {
                string guid = Guid.NewGuid().ToString().Replace("-", "");
                HtmlElement iframe = (HtmlElement)this.HtmlPresenter.Children[0];
                // Set an ID to the IFrame so that can be used later when calling the javascript   
                iframe.SetAttribute("id", guid);
                string code = "document.getElementById('" + guid + "').contentWindow.SetHtml('" + value + "');";
                HtmlPage.Window.Eval(code);
            }
        }
    }
0
Ivan
Top achievements
Rank 1
answered on 27 Dec 2010, 01:31 PM

In my case the Url to open in the RadHtmlPlaceHolder is a Silverlight application, so when in the UrlLoaded event I did:

HtmlElement iframe = (HtmlElement)myHtmlPlaceHolder.HtmlPresenter.Children[0];
HtmlWindow contentWindow = iframe.GetProperty("contentWindow") as HtmlWindow;
HtmlDocument document = contentWindow.GetProperty("document") as HtmlDocument;

But document is always null, I suposse because the silverlight has not loaded yet. Is there any way to wait the silverlight inside the RadHtmlPlaceHolder is already loaded before to get the HtmlDocument?
0
Tina Stancheva
Telerik team
answered on 30 Dec 2010, 10:37 AM
Hi James,

When you say that "the Url to open in the RadHtmlPlaceHolder is a Silverlight application" do you refer to a local Silverlight project or an external Silverlight page? Because if the SourceUrl is an external page, you cannot read any of the src document's properties due to security restrictions. If however, you set the SourceUrl to a local page, you should be able to get the HtmlDocument property when the UrlLoaded() event is fired even if the Silverlight page is still loading its content.

All the best,
Tina Stancheva
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
HTMLPlaceHolder
Asked by
Telemetry
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Telemetry
Top achievements
Rank 1
Kiril Stanoev
Telerik team
Shaikh Ahmad
Top achievements
Rank 1
Ivan
Top achievements
Rank 1
Share this question
or