<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Accordion Tips and Tricks</title> <style type="text/css"> .accordionHeader { color: white; background-color: #719DDB; font: bold 11px auto "Trebuchet MS", Verdana; font-size: 12px; cursor: pointer; padding: 4px; margin-top: 3px; } .accordionContent { background-color: #DCE4F9; font: normal 10px auto Verdana, Arial; border: 1px gray; padding: 4px; padding-top: 7px; }</style> <script type="text/javascript"> // Add the scripts shown in the tips over here</script></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <cc1:Accordion ID="AccordionCtrl" runat="server" SelectedIndex="0" HeaderCssClass="accordionHeader" ContentCssClass="accordionContent" AutoSize="None" FadeTransitions="true"> <Panes> <cc1:AccordionPane ID="AccordionPane0" runat="server"> <Header>Pane 1</Header> <Content> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </Content> </cc1:AccordionPane> <cc1:AccordionPane ID="AccordionPane1" runat="server"> <Header>Pane 2</Header> <Content> Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </Content> </cc1:AccordionPane> <cc1:AccordionPane ID="AccordionPane2" runat="server"> <Header>Pane 3</Header> <Content> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </Content> </cc1:AccordionPane> <cc1:AccordionPane ID="AccordionPane3" runat="server"> <Header>Pane 4</Header> <Content> Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. </Content> </cc1:AccordionPane> </Panes> </cc1:Accordion> </div> </form></body></html>
<script type="text/javascript"> function pageLoad() { AddPaneAtRuntime(); } function AddPaneAtRuntime() { var newAccordion = $find("AccordionCtrl_AccordionExtender"); var header = document.createElement("div"); header.innerText = "Pane 5"; header.className = "accordionHeader"; //set header css var content = document.createElement("div"); content.innerText = " This pane was added using JavaScript"; content.className = "accordionContent"; // set content css newAccordion.get_element().appendChild(header); newAccordion.get_element().appendChild(content); newAccordion.addPane(header,content); } </script>Using CodebehindC#protected void Page_Load(object sender, EventArgs e){ AccordionPane newAccordion = new AccordionPane(); newAccordion.HeaderContainer.Controls.Add(new LiteralControl("Pane 5")); newAccordion.ContentContainer.Controls.Add(new LiteralControl("This pane was added using Code Behind")); AccordionCtrl.Panes.Add(newAccordion);}VB.NETProtected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim newAccordion As New AccordionPane() newAccordion.HeaderContainer.Controls.Add(New LiteralControl("Pane 5")) newAccordion.ContentContainer.Controls.Add(New LiteralControl("This pane was added using Code Behind")) AccordionCtrl.Panes.Add(newAccordion)End Sub
<script type="text/javascript"> function pageLoad() { hideAccordionPane(1); } // hides pane 1 function hideAccordionPane(paneno) { $find('AccordionCtrl_AccordionExtender').get_Pane(paneno).header.style.display="none"; $find('AccordionCtrl_AccordionExtender').get_Pane(paneno).content.style.display="none"; } </script>
<script type="text/javascript"> function pageLoad() { changeSelected(2); // expand pane 3 } // expand given accordion pane function changeSelected(idx) { $find('AccordionCtrl_AccordionExtender').set_SelectedIndex(idx); } </script>
<script type="text/javascript"> function pageLoad() {var accCtrl = $find('AccordionCtrl_AccordionExtender'); accCtrl.add_selectedIndexChanged(onAccordionPaneChanged); } function onAccordionPaneChanged(sender, eventArgs) { var selPane = sender.get_SelectedIndex() + 1; alert('You selected Pane ' + selPane); } </script>I got this tip from the asp.net forums and was written by JonathanShen
<script type="text/javascript"> function pageLoad() { AddMouseOverToAccordion(); } function AddMouseOverToAccordion() { var acc = $find('AccordionCtrl_AccordionExtender'); for(paneIdx = 0; paneIdx < acc.get_Count(); paneIdx++) { $addHandler(acc.get_Pane(paneIdx).header,"mouseover",acc._headerClickHandler); } } </script>
<script type="text/javascript"> function pageLoad() { RemoveHandlerAtRuntime(2); } function RemoveHandlerAtRuntime(pane) { $removeHandler($find('AccordionCtrl_AccordionExtender').get_Pane(pane).header,"click",$find('AccordionCtrl_AccordionExtender')._headerClickHandler); } </script>
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: