Solved

Auto open accordian in asp.net

Posted on 2013-06-24
6
321 Views
Last Modified: 2013-10-15
I have an asp/ajax accordion on my page. What I would like to do is have it open and close automatically and loop through. I did find a script that will change the selected index (this works fine)

 <script type="text/javascript">
         function pageLoad() {
             changeSelected(1);
         }

         // expand given accordion pane
         function changeSelected(idx) {
             $find('Accordion1_AccordionExtender').set_SelectedIndex(idx);
         }
    </script>

Is it possible to modify this script to... lets say every 30 seconds, open the next unselected index and so on until it's get to the end, then start over at 0?

Thanks for any help.
0
Comment
Question by:someonenamedbrendan
  • 4
  • 2
6 Comments
 
LVL 14

Expert Comment

by:dejaanbu
ID: 39274129
just an idea:

if you are sure about the number of panes, ...say 5

(UNTESTED CODE)

var idx=0;
changeSelected(); //for initial select

setInterval(changeSelected,30000);

 function changeSelected() {
if(idx>4) {  idx =0;}
             $find('Accordion1_AccordionExtender').set_SelectedIndex(idx); idx++;
         }
0
 

Author Comment

by:someonenamedbrendan
ID: 39274915
thanks. I'll try it and see if I can make it work... but I never know how many panes I'm going to have.
0
 
LVL 14

Expert Comment

by:dejaanbu
ID: 39276971
getting the count is easyy:

add  a server side function (C#)

 public int getCount(){
           return MyAccordion.Panes.Count();
       }

in js,

add one more variable for storing the count first;

var totalPanes = <%= getCount()%>;
var idx=0;
changeSelected(); //for initial select

setInterval(changeSelected,30000);

 function changeSelected() {
if(idx>totalPanes ) {  idx =0;}
             $find('Accordion1_AccordionExtender').set_SelectedIndex(idx); idx++;
         }
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:someonenamedbrendan
ID: 39278151
thanks. I'll try it.
0
 

Accepted Solution

by:
someonenamedbrendan earned 0 total points
ID: 39563293
I ended up using the timer control
0
 

Author Closing Comment

by:someonenamedbrendan
ID: 39573134
because it was the answer.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now