document.getElementById is null after RadHtmlPlaceHolder had collapsed

7 posts, 1 answers
  1. Nazar
    Nazar avatar
    8 posts
    Member since:
    May 2011

    Posted 16 May 2011 Link to this post


    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);


  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 May 2011 Link to this post

    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
  3. DevCraft banner
  4. Nazar
    Nazar avatar
    8 posts
    Member since:
    May 2011

    Posted 20 May 2011 Link to this post

    Thanks, it was useful!
  5. Chris
    Chris avatar
    2 posts
    Member since:
    Feb 2011

    Posted 16 Aug 2011 Link to this post

    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? 
  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 19 Aug 2011 Link to this post

    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 >>

  7. Chris
    Chris avatar
    2 posts
    Member since:
    Feb 2011

    Posted 19 Aug 2011 Link to this post

    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? 
  8. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 24 Aug 2011 Link to this post

    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 >>

Back to Top
DevCraft banner