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

document.getElementById is null after RadHtmlPlaceHolder had collapsed

6 Answers 137 Views
HTMLPlaceHolder
This is a migrated thread and some comments may be shown as answers.
Nazar
Top achievements
Rank 1
Nazar asked on 16 May 2011, 05:51 PM


Good day, Telerik team!

I’m using RadHtmlPlaceHolder to play and control Flash movies.

SL interacts with Flash using JavaScript and Flash ExternalInterface.

Interaction is like in this article http://www.telerik.com/support/kb/silverlight/htmlplaceholder/htmlplaceholder-javascript.aspx

I have a problem with RadHtmlPlaceHolder after I set its Visibility property to Visibility.Collapsed.


Let’s suppose when video playing I’m clicking on a button, on button handler video is paused by calling specified JavaScript function and PlaceHolder’s Visibility property is setting to Visibility.Collapsed. Because instead of RadHtmlPlaceHolder I want to show some info. Then I’m clicking on another button (e.g. hide info), and RadHtmlPlaceHolder’s Visibility property is settings to Visibility.Visible, and then I want to continue play video by calling another JavaScript function. But when my code reaches “document.getElementById(‘myID’);” I’m getting NullReferenceException.

I looked at Html page in IE debugger and found that when RadHtmlPlaceHolder is collapsed, it’s disappears from there.

And then if I ignore IE error message and continue execution, iframe is appears again but in the end of page. With the same Id as before. Look at attached screenshots.

Seems to be my code is calling when iframe is missing from page.

Any suggestions? Can it be solved?

I tried to reset Id:

HtmlElement iframe = HtmlPage.Window.Eval(string.Format(@"document.getElementById('{0}');", "myIFrame" + _id)) as HtmlElement;

if (iframe == null)

{

    ((HtmlElement)htmlPlaceholder.HtmlPresenter.Children[0]).SetAttribute("id", "myIFrame" + _id);

}

It doesn’t work.

Here is an example of calling JavaScript

code = string.Format(@"document.getElementById('{0}').contentWindow.continueFLV();", "myIFrame" + _id);

HtmlPage.Window.Eval(code);


6 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 19 May 2011, 02:57 PM
Hi Nazar,

Currently, when RadHtmlPlaceholder is Collapsed, it is actually being removed from the DOM tree of the aspx page. However, could you please check out my test project where I prepared a workaround for you. I just use the Height and MinHeight of the RadHtmlPlaceholder set to 0 instead of playing with Visibility. Please let me know if it fits in your scenario.

All the best,
Petar Mladenov
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
Nazar
Top achievements
Rank 1
answered on 20 May 2011, 07:10 PM
Thanks, it was useful!
0
Chris
Top achievements
Rank 1
answered on 17 Aug 2011, 01:41 AM
But when making it reappear, what height to use?  Currently I want it to expand to the full height available, but what to set it to? 
0
Petar Mladenov
Telerik team
answered on 19 Aug 2011, 02:39 PM
Hi Chris,

 You can use the sizes (ActualWidth and ActualHeight) of the HTMLPlaceHolder's parent container like so;

private void Button_Click_2(object sender, RoutedEventArgs e)
       {
           this.RadHtmlPlaceholder1.Width = (this.RadHtmlPlaceholder1.Parent as Canvas).ActualWidth;
           this.RadHtmlPlaceholder1.Height = (this.RadHtmlPlaceholder1.Parent as Canvas).ActualHeight;
       }
Please let us know if this is suitable for you.Greetings,
Petar Mladenov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Chris
Top achievements
Rank 1
answered on 20 Aug 2011, 01:34 AM
Instead of specifying the exact size (because my htmlplaceholder is set to expand the width and height of the container), can I specify stretch?  How after I've set the width and height to 0? 
0
Petar Mladenov
Telerik team
answered on 24 Aug 2011, 04:21 PM
Hi Chris,

 Unfortunately you cannot  just "expand" the RadHtmlPlaceholder without specifying Width and Height after you have set them to 0.

Best wishes,
Petar Mladenov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
HTMLPlaceHolder
Asked by
Nazar
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Nazar
Top achievements
Rank 1
Chris
Top achievements
Rank 1
Share this question
or