Set focus of TextBox when AccordionPane is opened

Posted on 2007-10-12
Last Modified: 2010-05-18
I have set up a page with an Accordion control and 4 AccordionPanes each containing a Panel with a form for searching with a TextBox and various other options. Everything is working fine but I would like to set the focus of the TextBox in the selected AccordionPane when it is opened. I presume this should be done client side but can't see how to do it.
Question by:DerekWatling
    LVL 13

    Expert Comment


    y cant u call a javascript for setting focus
    when the panel is loaded

    b u d d h a

    Author Comment

    To clarify: I want to reset to focus each time a different AccordionPane is selected but can't work out how to detect this event.
    LVL 2

    Accepted Solution

    You need to set this up client side. Put this JavaScript at the bottom of your .aspx page where "accordionControl" is the ID of the Accordion control and "tb0", "tb1", ... are the IDs of the respective TextBoxes.

    <script type="text/javascript" language="javascript">

    function accordionInit() {
        var behavior = $get("<%=accordionControl.ClientID%>").AccordionBehavior;

    function accordionSelectedChange(sender, eventArgs) {
        if (eventArgs.get_propertyName() == "SelectedIndex") {
            switch (sender.get_ClientState()) {
                case "0":
                case "1":

    var prm = Sys.WebForms.PageRequestManager.getInstance();

    Author Comment

    I don't fully understand how this is working, but it does.


    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    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…

    734 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

    17 Experts available now in Live!

    Get 1:1 Help Now