Jquery tabs and asp.net homepage

I have a website with main pages and content pages. homepage code:

<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site.master.vb" Inherits="ProjectX1.Site" %> <!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></title> <asp:ContentPlaceHolder ID="head" runat="server"> </asp:ContentPlaceHolder> <link href="css/style.css" rel="stylesheet" type="text/css" /> <link href="css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css" /> </head> <body style="height: 800px"> <form id="form1" runat="server"> <div id="TopNav"> <ul> <li><a href="TopDeals.aspx">Top Deals</a></li> <li><a href="AllDeals.aspx">All Deals</a></li> <li><a href="Account.aspx">Account</a></li> <li> <asp:TextBox ID="SearchBox" runat="server"></asp:TextBox> <asp:Button ID="Search" runat="server" Text="Search" /> </li> </ul> </div> <div> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> </form> <!--Adding jQuery--> <script src="scripts/jquery/jquery-1.7.1.min.js" type="text/javascript"></script> <script src="scripts/jquery/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script> <!--JavaScript and jQuery functions--> <script type="text/javascript"> $(document).ready(function () { $("#TopNav").tabs(); }); </script> </body> </html> 

And my content pages are like:

 <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="TopDeals.aspx.vb" Inherits="ProjectX1.TopDeals" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> Top deals page. </asp:Content> 

The tabs now display fine, but the text used inside the tabs or

displayed again in each content of each tab.

Screenshot of how to do this: enter image description here

And here is the rendered HTML:

 <!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><title> </title> <link href="css/style.css" rel="stylesheet" type="text/css" /><link href="css/ui-lightness/jquery-ui-1.8.18.custom.css" rel="stylesheet" type="text/css" /></head> <body style="height: 800px"> <form method="post" action="TopDeals.aspx" id="form1"> <div class="aspNetHidden"> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTY1NDU2MTA1MmRkc9+hm0xMYZPW5kzqPGh5scwv9zQtVHHjF3TK0OClx8M=" /> </div> <div class="aspNetHidden"> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwLG75v1DwKuh5WeCAKF1vrqBsex0rMLZ1SKDXK1SSR/NgIGfr4ldbcVrFvXw7cqxVna" /> </div> <div id="TopNav"> <ul> <li><a href="TopDeals.aspx">Top Deals</a></li> <li><a href="AllDeals.aspx">All Deals</a></li> <li><a href="Account.aspx">Account</a></li> <li> <input name="ctl00$SearchBox" type="text" id="SearchBox" /> <input type="submit" name="ctl00$Search" value="Search" id="Search" /> </li> </ul> </div> <div> Top deals page. </div> </form> <!--Adding jQuery--> <script src="scripts/jquery/jquery-1.7.1.min.js" type="text/javascript"></script> <script src="scripts/jquery/jquery-ui-1.8.18.custom.min.js" type="text/javascript"></script> <!--JavaScript and jQuery functions--> <script type="text/javascript"> $(document).ready(function () { $("#TopNav").tabs(); }); </script> </body> </html> 

Can anyone tell me what I'm doing wrong here?

+4
source share
1 answer

The behavior you see matches the jQuery tabs - you are not using it correctly.
One of the typical use cases will have markup, for example:

 <div id="tabs"> <ul> <li><a href="#tabs-1">First Tab</a></li> <li><a href="#tabs-2">Second Tab</a></li> </ul> <div id="tabs-1"> Tab 1 Content </div> <div id="tabs-2"> Tab 2 Content </div> </div> 

Pay attention to the local href link to li and the corresponding tab div div (with the same identifier).

In the case of using URLs, the jquery tabs will automatically create the contents of the div and load them using AJAX (see contents via the AJAX exaple - http://jqueryui.com/demos/tabs/#ajax ).

This applies to your code, you are using urls - jquery loads the contents of the url in the tab. Thus, for the first tab, you can see the contents of the TopDeals.aspx page - and the same wizard is used on this page, and therefore the tab markup appears in the content section.

EDIT : workaround

First, opening a new page using a tab is not approved by usability experts - check out http://www.useit.com/alertbox/tabs.html ! However, to achieve what you want, you need to set the href of the active tab to a local link.

For example, on the main page

 <div id="TopNav"> <ul> <li><a href="TopDeals.aspx" runat="server" id="Tab1" >Top Deals</a></li> <li><a href="AllDeals.aspx" runat="server" id="Tab2" >All Deals</a></li> <li><a href="Account.aspx" runat="server" id="Tab3" >Account</a></li> <li> <asp:TextBox ID="SearchBox" runat="server"></asp:TextBox> <asp:Button ID="Search" runat="server" Text="Search" /> </li> </ul> <div id="TabContent"> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </div> </div> 

Pay attention to the placement of the content placeholder. Now on each page you need to configure the active href tab accordingly. For example, in TopDeals.aspx, you should add the following line to say page_load or page_prerender:

 Tab1.HRef = "#TabContent"; 

Instead of using hard-coded tab identifiers, etc. I would suggest using a repeater on the main page and populating it with code. Thus, you can open the ActiveTab property on the main page (specified by the content pages), which will adjust the href of the correct tab.

Finally, the last part is the navigation tab: see this FAQ on jquery tabs so that when you click another tab, the browser will open this page (instead of this content downloaded via AJAX).

EDIT . It looks like the above FAQ has been removed by the jquery team. To follow the tab url, you need to select a descriptor select event - for example,

 $('.tabs').tabs({ select: function(event, ui) { var url = $.data(ui.tab, 'load.tabs'); location.href = url; // follow url return false; // to disable default handling } }); 
+4
source

Source: https://habr.com/ru/post/1398534/


All Articles