Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to use AJAX CollapsiblePanelExtender in ASP.NET

Author: Jeff Nava
Download Source Code : 1423_AjaxCollapsiblePanelExtender.zip

In this article, we will see how we can use CollapsiblePanelExtender of AJAX Control Toolkit in ASP.NET.

 

 
CollapsiblePanelExtender in one the several Extender controls in AJAX Control Toolkit that are very useful and demanded in ASP.NET websites. It is used to expand and collapse webpage contents and controls using Panel control. CollapsiblePanelExtender uses ASP.NET panel to expand and collapse webpage contents. It is a simple, easy and cool way to collapse and expand ASP.NET Panel control and contents in Panel control. A Label control or a LinkButton control can be used with Panel control for expanding and collapsing web pages contents and controls. We can expand contents on single click and in the same way we can collapse contents by clicking again. The good news is that collapsing and expanding will not do a server side post back and page will not be refreshed. The look and layout can be changed using CSS and we can also add images and text for expand or show contents and collapse or hide contents. We can also control expand and collapse behavior using code. Both client side JavaScript and Server side code is available to achieve this functionality.
 
Properties of CollapsiblePanelExtender
 
TargetControlID:
 
The ID of the Panel Control which we have to expand and collapse.
 
ExpandControlID:
 
The ID of the Control we need to click to expand our Panel control.
 
CollapseControlID:
 
The ID of the Control we need to click to collapse our Panel control. ExpandControlID and CollapseControlID can be same.
 
TextLabelID:
 
The ID of the Label to display any text for status of the Panel or to guide user.
 
ExpandedText:
 
Text to display on the label which will appear when the panel is in expanded state.
 
CollapsedText:
 
Text to display on the label which will appear when the panel is in collapsed state.
 
ImageControlID:
 
The ID of the Image control which will be used to show the expanded and collapsed status of the panel.

ExpandedImage:
 
Path of the image which will appear when panel is in expanded state.
 
CollapsedImage:
 
Path of the image which will appear when panel is in collapsed state.
 
Collapsed:
 
It specifies the initial collapsed or expanded state of the panel. If we set Collapsed to true then the panel will be at collapsed state initially.

 

 

  1. Open Visual Studio 2010
  2. File > New > Website
  3. Visual basic or Visual C# > ASP.NET Empty Web Site
  4. Website > Add New Item > Web Form
  5. Open Toolbox > Right Click > Add Tab
  6. Name the Tab As “AJAX Control Toolkit”
  7. Click on Tab > Choose Items
  8. Browse the “AjaxControlToolkit.dll” > Click Ok
  9. I have downloaded and extracted AJAX Control Toolkit in “Ajax” folder in “C” Drive so my path to the file is “C:\Ajax\ AjaxControlToolkit.dll”
  10. Open web form and add a ScriptManager control from “AJAX Extensions” tab.

    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
     
    ScriptManager control is necessary when you are using Ajax functionality in your application.

     
  11. Add following CSS classes in style tag

    <style type="text/css">
           .table1
           {
                  background-color:Orange;
                  width:225px;
                  border-style:solid;
                  border-width:thin;
           }
           .table2
           {
                  background-color:Lime;
                  width:225px;
                  border-style:solid;
                  border-width:thin;
           }
           .textbox
           {            
                  background-color:Silver;
                  border-style:solid;
                  border-width:thin;
           }
           .button
           {
                  font-size:large;
                  background-color:Fuchsia;
                  border-style:solid;
                  border-width:thin;
           }
    </style>

     
  12. Add following code in form tag

    <div>
           <asp:ScriptManager ID="ScriptManager1" runat="server">
           </asp:ScriptManager>
           <asp:Panel ID="Panel1" runat="server" >
                  <table class="table1" >
                         <tr>
                          <td align="left">
                               <b>Fill the below form:</b>
                          </td>
                          <td align="right">
                                <asp:Label ID="lblShowHide" runat="server" ></asp:Label>
                                <asp:Image ID="imgShowHide" runat="server" />
                          </td>
                         </tr>               
                  </table>
           </asp:Panel>
           <asp:Panel ID="Panel2" runat="server">
                  <table class="table2">
                         <tr>
                               <td>Last Name</td>
                               <td>
                                      <asp:TextBox ID="txtBoxLastName" runat="server" CssClass="textbox"></asp:TextBox>
                               </td>
                         </tr>
                         <tr>
                               <td>First Name</td>
                               <td>
                                      <asp:TextBox ID="txtBoxFirstName" runat="server" CssClass="textbox"></asp:TextBox>
                               </td>
                         </tr>
                         <tr>
                               <td>Age</td>
                               <td>
                                      <asp:TextBox ID="txtBoxAge" runat="server" CssClass="textbox"></asp:TextBox>
                               </td>
                         </tr>
                         <tr>
                               <td>Phone No.</td>
                               <td>
                                      <asp:TextBox ID="txtPhone" runat="server" CssClass="textbox"></asp:TextBox>
                               </td>
                         </tr>
                         <tr>
                               <td>City</td>
                               <td>
                                      <asp:TextBox ID="txtBoxCity" runat="server" CssClass="textbox"></asp:TextBox>
                               </td>
                         </tr>
                         <tr>
                               <td>Country</td>
                               <td>
                                      <asp:TextBox ID="txtBoxCountry" runat="server" CssClass="textbox"></asp:TextBox>
                               </td>
                         </tr>
                         <tr>
                               <td colspan="2" align="center">
                                      <asp:Button ID="btnSignup" runat="server" Text="Signup" CssClass="button" />
                               </td>
                         </tr>
                  </table>
           </asp:Panel>
           <asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server"
           TargetControlID="Panel2" ExpandControlID="panel1" CollapseControlID="Panel1"
           ExpandedText="Hide" CollapsedText="Show" TextLabelID="lblShowHide" ImageControlID="imgShowHide"
           ExpandedImage="Images/ArrowHide.jpg" CollapsedImage="Images/ArrowShow.jpg" Collapsed="true" >
           </asp:CollapsiblePanelExtender>
    </div>
     
    You can see above, I have added two Panel controls. Panel1 will be use as expand and collapse control. You can see in CollapsePanelExtender control, I have mentioned ExpandControlID and CollapseControlID as Panel1. In Panel1, I have added a table and one row and two cells in the table. In second cell, I have added a Label control and an Image control. We will use these Label and Image controls to display the text and images for expand and collapse status.
    Second Panel is our target control that will be used to expand and collapse the content in this panel. In second Panel, I have added a table and some TextBox controls and a button. I have also mentioned CSS classes for tables, TextBox and Button controls.
     
  13. Now see the website in browser

 

 

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to access a user control from another user control in ASP.NET

Disclaimer - Privacy
© 2002-2017 DevASP.net