Skip to main content

Sample Code for Accordion Control in AJAX

Here I will explain how to use the Ajax Accordion control in asp.net.

The Accordion is a web control that allows you to provide multiple panes and display them one at a time. It is like having several CollapsiblePanels where only one can be expanded at a time. The Accordion is implemented as a web control that contains AccordionPane web controls. Each AccordionPane control has a template for its Header and its Content. We keep track of the selected pane so it stays visible across postback

Below are the properties for Accordion control

SelectedIndex - This property is used to set initial AccordionPane to be visible.

HeaderCssClass – This CSS class property is used to apply style to Header of all AccordionPanes.

HeaderSelectedCssClass – This CSS class is used to change the color of selected AccordionPane.

ContentCssClass – This CSS class is used to update the AccordionPane.

FadeTransitions – This Property is used to set True to use the fading transition effect, false for standard transitions.

TransitionDuration – This Property is used to set the Number of milliseconds to animate the transitions

FramesPerSecond - This Property is used to set the Number of frames per second used in the transition animations.

RequireOpenedPane – This Property is used to Prevent closing the currently opened pane when its header is clicked (which ensures one pane is always open). The default value is true.

SuppressHeaderPostbacks – This Property is Prevent the client-side click handlers of elements inside a header from firing (this is especially useful when you want to include hyperlinks in your headers for accessibility)

AutoSize – This Property is used to set the height of the accordion control. This Property contains 3 types of varieties

1. None- The Accordion grows/shrinks without restriction
2. Auto- the Accordion never grows larger than the value specified by its Height property.
3. Fill- The Accordion always stays the exact same size as its Height property
Panes - Collection of AccordionPane controls

HeaderTemplate - The Header template contains the markup that should be used for an pane's header when databinding

ContentTemplate - The Content template contains the markup that should be used for a pane's content when databinding

Example 

Now we can see how to use accordion control in our application for those first add AjaxControlToolkit reference to your application and add 

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

And 

<asp:ScriptManager ID="ScriptManager1" runat="server" />

HTML

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Accordion Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <ajaxToolkit:Accordion runat="server" ID="theAccordion" SelectedIndex="0" AutoSize="Limit"
            BackColor="#E1E1E1" FadeTransitions="true" TransitionDuration="333" FramesPerSecond="30"
            Width="200px" Font-Names="Verdana" Font-Size="Smaller">
            <Panes>
                <ajaxToolkit:AccordionPane ID="AccordionPane1" runat="server">
                    <Header>
                        <div style="background: #C2A6FF; font-size: medium; cursor: hand; border: 1px Solid #000000;">
                            Menu 1
                        </div>
                    </Header>
                    <Content>
                        <div>
                            <ul style="list-style-type: none;">
                                <li><a href="#">Sub Menu 1</a>li>
                                    <li><a href="#">Sub Menu 2</a>li>
                                        <li><a href="#">Sub Menu 3</a>li>
                                            <li><a href="#">Sub Menu 4</a>li>
                                                <li><a href="#">Sub Menu 5</a>li>
                            </ul>
                        </div>
                    </Content>
                </ajaxToolkit:AccordionPane>
                <ajaxToolkit:AccordionPane ID="AccordionPane2" runat="server">
                    <Header>
                        <div style="background: #C2A6FF; font-size: medium; cursor: hand; border: 1px Solid #000000;">
                            Menu 2
                        </div>
                    </Header>
                    <Content>
                        <div>
                            <ul style="list-style-type: none;">
                                <li><a href="#">Sub Menu 1</a>li>
                                    <li><a href="#">Sub Menu 2</a>li>
                                        <li><a href="#">Sub Menu 3</a>li>
                                            <li><a href="#">Sub Menu 4</a>li>
                                                <li><a href="#">Sub Menu 5</a>li>
                            </ul>
                        </div>
                    </Content>
                </ajaxToolkit:AccordionPane>
                <ajaxToolkit:AccordionPane ID="AccordionPane3" runat="server">
                    <Header>
                        <div style="background: #C2A6FF; font-size: medium; cursor: hand; border: 1px Solid #000000;">
                            Menu 3
                        </div>
                    </Header>
                    <Content>
                        <div>
                            <ul style="list-style-type: none;">
                                <li><a href="#">Sub Menu 1</a>li>
                                    <li><a href="#">Sub Menu 2</a>li>
                                        <li><a href="#">Sub Menu 3</a>li>
                                            <li><a href="#">Sub Menu 4</a>li>
                                                <li><a href="#">Sub Menu 5</a>li>
                            </ul>
                        </div>
                    </Content>
                </ajaxToolkit:AccordionPane>
                <ajaxToolkit:AccordionPane ID="AccordionPane4" runat="server">
                    <Header>
                        <div style="background: #C2A6FF; font-size: medium; cursor: hand; border: 1px Solid #000000;">
                            Menu 4
                        </div>
                    </Header>
                    <Content>
                        <div>
                            <ul style="list-style-type: none;">
                                <li><a href="#">Sub Menu 1</a>li>
                                    <li><a href="#">Sub Menu 2</a>li>
                                        <li><a href="#">Sub Menu 3</a>li>
                                            <li><a href="#">Sub Menu 4</a>li>
                                                <li><a href="#">Sub Menu 5</a>li>
                            </ul>
                        </div>
                    </Content>
                </ajaxToolkit:AccordionPane>
            </Panes>
        </ajaxToolkit:Accordion>
    </div>
    </form>
</body>
</html>

 

For Download source code Click Here



Comments

Popular posts from this blog

Connected and disconnected architecture in ADO.Net with Example

Connected Architecture of ADO.NET The architecture of ADO.net, in which connection must be opened to access the data retrieved from database is called as connected architecture. Connected architecture was built on the classes connection, command, datareader and transaction.  Connected architecture is when you constantly make trips to the database for any CRUD (Create, Read, Update and Delete) operation you wish to do. This creates more traffic to the database but is normally much faster as you should be doing smaller transactions. Disconnected Architecture in ADO.NET The architecture of ADO.net in which data retrieved from database can be accessed even when connection to database was closed is called as disconnected architecture. Disconnected architecture of ADO.net was built on classes connection, dataadapter, commandbuilder and dataset and dataview. Disconnected architecture is a method of retrieving a recor

HTTPHandler and HTTPModule in ASP.NET

If you want to implement pre-processing logic before a request hits the IIS resources. For instance you would like to apply security mechanism, URL rewriting, filter something in the request, etc. ASP.NET has provided two types of interception HttpModule and HttpHandler .   The web server examines the file name extension of the requested file, and determines which ISAPI extension should handle the request. Then the request is passed to the appropriate ISAPI extension.  For Example When an .aspx page is requested it is passed to ASP.Net page handler. Then Application domain is created and after that different ASP.Net objects like Httpcontext, HttpRequest, HttpResponse. HTTPModule: -    It's just like a filter. The Modules are called before and after the handler executes . -    HTTP Modules are objects which also participate the pipeline but they work before and after the HTTP Handler does its job, and produce additional services within the pipeline -  

ASP.NET Page Life Cycle with example

In this article, we are going to discuss the different methods and order they are executed during the load of an .aspx web page. Methods Description Page_PreInit Before page Initialization Page_Init Page Initialization LoadViewState View State Loading LoadPostData Postback Data Processing Page_Load Page Loading RaisePostDataChangedEvent PostBack Change Notification RaisePostBackEvent PostBack Event Handling Page_PreRender Page Pre Rendering Phase SaveViewState View State Saving Page_Render Page Rendering Page_Unload Page Unloading PreInit : The entry point of the page life cycle is the pre-initialization phase called “PreInit”. You can dynamically set the values of master pages and themes in this event. You can also dynamically create controls in this event.  Init : This event fires after each control h