





















































In a nutshell, the jQuery UI library provides the following:
In this article, we will primarily take a look at integration of jQuery UI with ASP.NET to build rich content quickly and easily.
Read more: ASP.NET: Using jQuery UI Widgets
(Move the mouse over the image to enlarge.)
<script src="js/jquery-1.4.1.js" type="text/javascript"></script> <script src="js/jquery-ui-1.8.9.custom.min.js" type="text/javascript"></script>
<link href="css/sunny/jquery-ui-1.8.9.custom.css" rel="stylesheet" type="text/css" />
Now let's move on to the recipes and explore some of the powerful functionalities of jQuery UI.
The jQuery accordion widget allows the creation of collapsible panels on the page without the need for page refresh. Using an accordion control, a single panel is displayed at a time while the remaining panels are hidden.
<asp:Panel id="contentArea" runat="server"> <h3><a href="#">Section 1</a></h3> <asp:Panel ID="Panel1" runat="server"> Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </asp:Panel> <h3><a href="#">Section 2</a></h3> <asp:Panel ID="Panel2" runat="server"> Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </asp:Panel> <h3><a href="#">Section 3</a></h3> <asp:Panel ID="Panel3" runat="server"> Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. </asp:Panel> <h3><a href="#">Section 4</a></h3> <asp:Panel ID="Panel4" runat="server"> Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum </asp:Panel> </asp:Panel>
#contentArea
{
width: 300px;
height: 100%;
}
Our accordion markup is now ready. We will now transform this markup into an accordion control using the functionalities of jQuery UI.
In the document.ready() function of the jQuery script block, apply the accordion() method to the main content panel:
$("#contentArea").accordion();
Thus, the complete jQuery UI solution for the problem at hand is as follows:
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#contentArea").accordion();
});
</script>
Run the web page. The accordion control is displayed as shown in the following screenshot:
Click on the respective panel headers to display the required panels. Note that the accordion control only displays the active panel at a time. The remaining panels are hidden from the user.
For detailed documentation on the jQuery UI accordion widget, please visit http://jqueryui.com/demos/accordion/.
The jQuery UI tab widget helps to create tab controls quickly and easily on ASP.NET web pages. The tab control helps in organizing content on a page thus improving the presentation of bulky content. With the help of jQuery UI tab widget, the content can also be retrieved dynamically using AJAX.
In this recipe, we will see a simple example of applying this powerful widget to ASP.NET forms.
Thus the complete aspx markup of the web form is as shown next:
<form id="form1" runat="server">
<asp:panel id="contentArea" runat="server">
<ul>
<li><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
<li><a href="#tab4">Tab 4</a></li>
</ul>
<asp:panel ID="tab1" runat="server">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua.</p>
</asp:panel>
<asp:panel ID="tab2" runat="server">
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo consequat.</p>
</asp:panel>
<asp:panel ID="tab3" runat="server">
<p>Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. </p>
</asp:panel>
<asp:panel ID="tab4" runat="server">
<p>Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum</p>
</asp:panel>
</asp:panel>
</form>
Next, we will see how we can transform this markup into a tab control using jQuery UI.
In the document.ready() function of the jQuery script block, apply the tabs() method to the container panel as follows:
$("#contentArea").tabs();
Thus, the complete jQuery UI solution for creating the tab control is as follows:
<script language="javascript" type="text/javascript"
$(document).ready(function(){
$("#contentArea").tabs();
});
</script>
Run the web form. The page displays the tabbed content as follows:
Click on the respective tab headers to view the required content.
For detailed documentation on the jQuery UI tabs widget, visit the jQuery website.