Monday, March 26, 2012

Asp.net Ajax Accordion SelectedIndex Event

Hello. Im trying to catch the selected index property of an accordion control and then store it into a session variable that I can then load later on in my application. Anyone have any suggestions on how to make this happen...Thanks in advance.

Here you go. On postback, just grab the value of the textbox and assign it to a session variable. Some of the javascript is for dealing with finding form objects when using a master file.

/*** Code Behind ***/
for (int i = 0; i < YourAccordionName.Panes.Count; i++)
{
YourAccordionName.Panes[i].HeaderContainer.Attributes.Add("onclick", "AssignIndex(" + i.ToString() + ")");
}

/*** Source View ***/
<asp:TextBox
ID="txtAccordionSelectedIndex"
runat="server"
style="background-color:#FFFFFF; color:#FFFFFF; border:solid 0px #FFFFFF"
Text="-1" />

<script language="JavaScript">
<!--
function AssignIndex(val)
{
document.forms[0].<%= txtAccordionSelectedIndex.UniqueID%>.value = val;
}
//-->
</script>

Hope that helps.

No comments:

Post a Comment