Solved

Auto open accordian in asp.net

Posted on 2013-06-24
6
352 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

821 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