Scroll to bottom of HTMLPlaceHolder

3 posts, 0 answers
  1. Ólafur Gíslason
    Ólafur Gíslason avatar
    6 posts
    Member since:
    Mar 2007

    Posted 23 Apr 2010 Link to this post

    Hi, is it possible to scroll to the bottom of a HTMLPlaceHolder in code?

    I am adding to the HTMLSource and the HTMLPlaceHolder  always scrolls to the top?

    Before I tried to place the HTMLPlaceHolder   within a ScrollViewer but then it is impossible to get rid of the HTMLPlaceHolder Scrollbars.  I will get a double set of scrollbars.  It is no problem to scroll to the bottom of the ScrollViewer.

    I tried unsuccessfully to wire this up in the Page_Load event to get rid of the HTMLPlaceHolder scrollbar 

     (radHtmlPlaceholder1.HtmlPresenter.Children[0] as HtmlElement).SetAttribute("scrolling", "no");

    regards,
    Olafur


  2. Ólafur Gíslason
    Ólafur Gíslason avatar
    6 posts
    Member since:
    Mar 2007

    Posted 24 Apr 2010 Link to this post

    Well, it seems there is a simple solution.

    I went through all the posts here on this Forum  and used my trusted source Google.

    I host the Html Placeholder in a ScrollView.

           <ScrollViewer Height="122" HorizontalAlignment="Left" Margin="41,66,0,0" 
                Name="scrollStoryboard"     VerticalAlignment="Top"         Width="514">
                <telerik:RadHtmlPlaceholder Name="radHtmlStoryboard" />
            </ScrollViewer>

    Then on OnNavigatedTo event of my page I do a quick hide and show on the Placeholder and set the scolling and overflow properties.  I should be able to set these properties on the OnLoad event but it does not work.

                radHtmlStoryboard.Visibility = System.Windows.Visibility.Collapsed;
                radHtmlStoryboard.Visibility = System.Windows.Visibility.Visible;
                (radHtmlStoryboard.HtmlPresenter.Children[0] as HtmlElement).SetAttribute("scrolling", "no");
                (radHtmlStoryboard.HtmlPresenter.Children[0] as HtmlElement).SetAttribute("overflow", "visible");

    And whenever I write something to the HtmlSource, I call the UpdateLayout followed by the ScrollToVerticalOffset on the ScrollView

                        htmlText = transcript .MessageText  + "<br/>";
                        radHtmlStoryboard.HtmlSource += htmlText;

                        radHtmlStoryboard.UpdateLayout();
                        scrollStoryboard.ScrollToVerticalOffset(radHtmlStoryboard.ActualHeight);
      

    This works like a charm and scrolls to the bottom every time. The overflow property is needed if the output is too wide for the HtmlPlaceholder and forces a wrap on the HtmlPlaceholder and then a vertical scrollbar would appear.

    regards,
    Olafur

  3. DevCraft banner
  4. Kiril Stanoev
    Admin
    Kiril Stanoev avatar
    1512 posts

    Posted 28 Apr 2010 Link to this post

    Hello Ólafur,

    Thank you for sharing this workaround.

    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.
Back to Top