maintaining item scroll position thru a postback?

10 posts, 0 answers
  1. Marc
    Marc avatar
    21 posts
    Member since:
    Nov 2008

    Posted 11 Jan 2009 Link to this post

    Is there a way to maintain the scroll position of the rotator control thru a postback?

    I have a rotator at the top of my master page and it scrolls thru some images and data. The start position is 0 initially so after a ppost back it always goes back and restarts from 0.

    is there a way to maintain which item is being scrolled thru a postback?

  2. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 12 Jan 2009 Link to this post

    Hi Marc,


    You can achieve the desired behavior by storing the index of the currently showed RadRotator's item. For example you can store it in an HiddenField and then set this value to the InitialItemIndex property of the RadRotator control in code behind. e.g.:

    • create a JavaScript function and attach it to the OnClientClick event of the RadRotator control.

      JavaScript
    <script type="text/javascript"
        var currentIndex = 0; 
        var hiddenField = null
        function OnItemShown(sender, arg) 
        { 
            if (hiddenField == null)
            { // First loading
                hiddenField = document.getElementById("HiddenField1"); 
                currentIndex = hiddenField.value; 
            } 
            hiddenField.value = currentIndex; // Store the index
            var lastIndex = sender.get_items().length - 1;
            if (currentIndex == lastIndex) 
            { 
                currentIndex = 0; 
            } 
            else 
            { 
                currentIndex++; 
            } 
        } 
    </script>

    • assign the value of the HiddenField control to the InitialItemIndexin property of the RadRotator object e.g.
    C#
    protected void Page_Load(object sender, EventArgs e) 
        RadRotator1.InitialItemIndex = int.Parse(HiddenField1.Value); 


    VB.NET
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As EventArgs) Handles Me.Load 
           RadRotator1.InitialItemIndex = Integer.Parse(HiddenField1.Value) 
    End Sub 


    I hope this helps.

    All the best,
    Fiko
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marc
    Marc avatar
    21 posts
    Member since:
    Nov 2008

    Posted 12 Jan 2009 Link to this post

    OnClientClick event ....

    why the itemclick? I will not be clicking the item at all...

    plus there is the on itemclicked and onitemclicking but I dont se onitemclick...

    would it not be better if I tied the onItemshown or onitemshowing?
  5. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 13 Jan 2009 Link to this post

    Hi Marc,

    I apologize for the mistake - indeed, OnClientItemShown should be used. In the JavaScript code I have used this event, but I made the typo in the text before.

    Once again, sorry for the error.

    Best wishes,
    Fiko
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 09 Mar 2009 Link to this post

    Hi,

    I tried this approach - but it does not work at all.

    In my masterpage body I have
        <script type="text/javascript">  
                var currentIndex = 0;  
                var hiddenField = null;  
                function OnItemShown(sender, arg) {  
                    if (hiddenField == null) { // First loading  
                        hiddenField = $get('<%= hfRotatorIndex.ClientID %>');  
                        currentIndex = hiddenField.value;  
                    }  
                    hiddenField.value = currentIndex; // Store the index  
                    var lastIndex = sender.get_items().length - 1;  
     
                    if (currentIndex == lastIndex) {  
                        currentIndex = 0;  
                    }  
                    else {  
                        currentIndex++;  
                    }  
                    alert(hiddenField.value);  
                }   
            </script> 

    In Codebhind I have
            protected void Page_Load(object sender, EventArgs e) {  
                int nIDX;  
                if (int.TryParse(hfRotatorIndex.Value, out nIDX)) {  
                    rrRot.InitialItemIndex = nIDX;  
                }  
     
                if (!IsPostBack) {  
                    RebindRotator();  
                rrRot.OnClientItemShown = "OnItemShown";  
     

    The alert is just to test if it works on the client - and yes it does.
    With the first call it shows nothing - and then I get, 1, 2,...

    But in the page load hfRotatorIndex.Value is allways emtpy.

    I guess this has something to do with the fact that this is a masterpage - but I'm not sure.

    It would be great if you could help me out of this - because this is a real problem in my scenario.
    I rotate about 100 items in the top area of my masterpage.
    And every time a user changes a page rotator starts with the first item.

    Regards

    Manfred
  7. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 10 Mar 2009 Link to this post

    Hi Manfred,

    I tested the code in MasterPage scenario but unfortunately I was not able to reproduce the problem. Could you please open a new support ticket and send me a simple project that reproduce the problem? Once I have a better view over your exact setup I will be able to provide a solution.

    Best wishes,
    Fiko
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 10 Mar 2009 Link to this post

    Hi,

    I opened a ticket (196410) wich also includes the rotator problem (maintaning state in masterpage).

    Regards

    Manfred
  9. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 10 Mar 2009 Link to this post

    Hi,

    I opened a ticket (196410) wich also includes my object datasource problem.

    Regards

    Manfred
  10. Fiko
    Admin
    Fiko avatar
    1406 posts

    Posted 13 Mar 2009 Link to this post

    Hi Manfred,

    As I noted in my reply to your support ticket, the code will work with postback only. Currently the RadRotator control does not have a client side API that covers such scenario. The good news however, is that we plan to implement client side functionality (to extend the set_initialItemIndex() function) of the RadRotator control in one of the future updates.

    Sincerely yours,
    Fiko
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  11. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 13 Mar 2009 Link to this post

    I guess this would not help me in my scenario.
    My Problem is that I lose the Index at page changes.

    The only thing that could help is maintanning the current index somehow like RadPanel does it (in Sessionstate I think),

    Anyhow - it is what I do at the moment. I use the RadMenu handling the onclick server event - store the saved index (from the hidden field) and set it a the next masterpage load.

    Regards

    Manfred
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017