Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Auto open accordian in asp.net

Posted on 2013-06-24
6
Medium Priority
?
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

722 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