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

maintaining item scroll position thru a postback?

9 Answers 299 Views
Rotator
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 11 Jan 2009, 09:04 PM
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?

9 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 12 Jan 2009, 04:03 PM
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.
0
Marc
Top achievements
Rank 1
answered on 12 Jan 2009, 05:17 PM
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?
0
Fiko
Telerik team
answered on 13 Jan 2009, 08:26 AM
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.
0
ManniAT
Top achievements
Rank 2
answered on 09 Mar 2009, 09:56 AM
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
0
Fiko
Telerik team
answered on 10 Mar 2009, 02:31 PM
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.
0
ManniAT
Top achievements
Rank 2
answered on 10 Mar 2009, 04:28 PM
Hi,

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

Regards

Manfred
0
ManniAT
Top achievements
Rank 2
answered on 10 Mar 2009, 04:29 PM
Hi,

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

Regards

Manfred
0
Fiko
Telerik team
answered on 13 Mar 2009, 09:19 AM
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.
0
ManniAT
Top achievements
Rank 2
answered on 13 Mar 2009, 09:22 AM
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
Tags
Rotator
Asked by
Marc
Top achievements
Rank 1
Answers by
Fiko
Telerik team
Marc
Top achievements
Rank 1
ManniAT
Top achievements
Rank 2
Share this question
or