• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1205
  • Last Modified:

Set focus of TextBox when AccordionPane is opened

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.
0
DerekWatling
Asked:
DerekWatling
  • 2
1 Solution
 
jeebukarthikeyanCommented:
hi,

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


b u d d h a
0
 
DerekWatlingAuthor Commented:
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.
0
 
DrDekCommented:
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;
    behavior.add_propertyChanged(accordionSelectedChange);
}

function accordionSelectedChange(sender, eventArgs) {
    if (eventArgs.get_propertyName() == "SelectedIndex") {
        switch (sender.get_ClientState()) {
            case "0":
                $get("<%=tb0.ClientID%>").focus();
                break;
            case "1":
                $get("<%=tb1.ClientID%>").focus();
                break;
...
        }
    }
}

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(accordionInit);
</script>
0
 
DerekWatlingAuthor Commented:
I don't fully understand how this is working, but it does.

Thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now