jquery tabs and asp.net master pages issue

陌路散爱 提交于 2019-12-04 09:51:12
VinayC

The behavior that you are seeing is as per jQuery tabs - you are not using it correctly.
One of the typical use case scenario will have markup such as:

<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>

Note local referencing href on li and corresponding tab content div (with same id).

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

This is the case with your code, you are using urls - jquery is loading the url content in a tab. So, for first tab, you can see the content of TopDeals.aspx page - and this page use the same master and hence the tab markup appears in the content div.

EDIT: work-around

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

For example, in master 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>

Notice the placement of content placeholder. Now, in each page, you have to adjust the active's tab href accordingly. For example, in TopDeals.aspx, you have to add following line in say page_load or page_prerender:

Tab1.HRef = "#TabContent";

Instead of using hard-coded tab ids etc, I would suggest to use a Repeater in master page and populating it from code-behind. That way, you can expose ActiveTab property in master page (set by content pages) that will adjust href of the correct tab.

Finally last part is tab navigation: see this FAQ from jquery tabs so that when other tab is clicked, browser will open that page (instead of content getting loaded via AJAX).

EDIT: It appears that above FAQ has been removed by jquery team. To follow the tab URL, one needs handle select event - e.g.

$('.tabs').tabs({
  select: function(event, ui) {
     var url = $.data(ui.tab, 'load.tabs');
     location.href = url; // follow url
     return false; // to disable default handling
  }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!