<ul id="tabs">
<li><a href="#" name="#tab1"></a></li>
<li><a href="#" name="#tab2"></a></li>
<li><a href="#" name="#tab3"></a></li>
<li><a href="#" name="#tab4"></a></li>
<li><a href="#" name="#tab5"></a></li>
<li><a href="#" name="#tab6"></a></li>
<li><a href="#" name="#tab7"></a></li>
<li><a href="#" name="#tab8"></a></li>
</div>
<div id="tab2">
</div>
<div id="tab3">
</div>
<div id="tab4">
</div>
<div id="tab5">
</div>
<div id="tab6">
<table>
<tr>
<td style ="color: Black "><asp:DropDownList ID="ddlPageSize1" runat="server" AutoPostBack="True" onselectedindexchanged="ddlPageSize_SelectedIndexChanged1">
<asp:ListItem>10</asp:ListItem>
<asp:ListItem>25</asp:ListItem>
<asp:ListItem>50</asp:ListItem>
<asp:ListItem>100</asp:ListItem>
<asp:ListItem>250</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td colspan="6">
<asp:GridView ID="GridView2" runat="server" AllowPaging="True" AllowSorting="True" CurrentSortField="ActivityDate" CurrentSortDirection="ASC" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" AutoGenerateColumns="False" OnPreRender="GridView2_PreRender" OnSorting="GridView2_Sorting" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" GridLines="Vertical" OnRowCommand="GridView2_RowCommand" OnRowCreated="GridView2_RowCreated" >
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="username" HeaderText="username" SortExpression="username" />
<asp:BoundField DataField="ActivityDate" HeaderText="ActivityDate" SortExpression="ActivityDate" />
<asp:BoundField DataField="Action" HeaderText="Action" SortExpression="Action" />
<asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
<asp:BoundField DataField="Outcome" HeaderText="Outcome" SortExpression="Outcome" />
<asp:TemplateField HeaderText="File" ShowHeader="False"> <ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False"
CommandArgument='<%# Eval("ImportedFilename") %>'
CommandName="Download" Text='<%# Eval("ImportedFilename") %>'>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="#999999" Font-Bold="True" ForeColor="Black" BorderStyle="Dashed" BorderWidth="1" BorderColor="Black" Font-Size="Medium" Font-Names="Arial" />
<PagerStyle ForeColor="#330099" HorizontalAlign="Center" BorderStyle="None" />
<RowStyle BackColor="White" BorderStyle="Solid" BorderWidth="1" BorderColor="Black" Font-Size="Medium" HorizontalAlign="Center" ForeColor="Black"/>
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
</td>
</tr>
<tr>
<td> </td>
<td> <asp:Label ID="Label5" runat="server" Text="Label"></asp:Label></td>
<td style ="color: Black "> Page Number:<asp:DropDownList ID="ddlPageNumbers1" runat="server" AutoPostBack="True" onselectedindexchanged="ddlPageNumbers_SelectedIndexChanged1"></asp:DropDownList></td>
</tr>
</table>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" SelectMethod="GetAllImportLogs" TypeName="demo.ImportLogAccessLayer">
<SelectParameters>
<asp:Parameter Name="pageIndex" Type="Int32" />
<asp:Parameter Name="pageSize" Type="Int32" />
<asp:Parameter Name="sortExpression" Type="String" />
<asp:Parameter Name="sortDirection" Type="String" />
<asp:Parameter Direction="Output" Name="totalRows" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</div>
<div id="tab7">
</div>
<div id="tab8">
</div>
function resetTabs() {
$("#content > div").hide(); //Hide all content
$("#tabs a").attr("id", ""); //Reset id's
}
var myUrl = window.location.href; //get URL
var myUrlTab = myUrl.substring(myUrl.indexOf("#")); // For localhost/tabs.html#tab2, myUrlTab = #tab2
var myUrlTabName = myUrlTab.substring(0, 4); // For the above example, myUrlTabName = #tab
Sys.Application.add_Load(tabs);
(function tabs() {
$("#content > div").hide(); // Initially hide all content
$("#tabs li:first a").attr("id", "current"); // Activate first tab
$("#content > div:first").fadeIn(); // Show first tab content
$("#tabs a").on("click", function (e) {
e.preventDefault();
if ($(this).attr("id") == "current") { //detection for current tab
return
}
else {
resetTabs();
$(this).attr("id", "current"); // Activate this
$($(this).attr('name')).fadeIn(); // Show content for current tab
}
});
for (i = 1; i <= $("#tabs li").length; i++) {
if (myUrlTab == myUrlTabName + i) {
resetTabs();
$("a[name='" + myUrlTab + "']").attr("id", "current"); // Activate url tab
$(myUrlTab).fadeIn(); // Show url tab content
}
}
})()
当我尝试在选项卡6中使用下拉列表时,它会重置为选项卡1.下拉列表工作正常,但我必须再次单击选项卡6以查看结果。我尝试用几种方法解决它,它没有用。任何帮助将不胜感激,以防止标签重置。
答案 0 :(得分:1)
在Sys.Application.add_load( //your code here)
ready
DOM
内添加您的Jquery代码
编辑2(删除重置标签功能并直接在add_load中调用
<script type="text/javascript">
$(document).ready(function () {
Sys.Application.add_load(function () {
$("#content > div").hide(); //Hide all content
$("#tabs a").attr("id", ""); //Reset id's
$("#content > div").hide(); // Initially hide all content
$("#tabs li:first a").attr("id", "current"); // Activate first tab
$("#content > div:first").fadeIn(); // Show first tab content
$("#tabs a").on("click", function (e) {
e.preventDefault();
if ($(this).attr("id") == "current") { //detection for current tab
return
}
else {
resetTabs();
$(this).attr("id", "current"); // Activate this
$($(this).attr('name')).fadeIn(); // Show content for current tab
}
});
for (i = 1; i <= $("#tabs li").length; i++) {
if (myUrlTab == myUrlTabName + i) {
resetTabs();
$("a[name='" + myUrlTab + "']").attr("id", "current"); // Activate url tab
$(myUrlTab).fadeIn(); // Show url tab content
}
}
});
});
</script>
答案 1 :(得分:0)
当您从下拉列表中选择值时,您的页面PostBack(很可能是需求)。现在这篇文章将您带到服务器端,核心问题是您没有告诉服务器您是否在第6个选项卡上。
将选项卡ID传递给服务器,以便在回发返回时,它将检查选项卡ID并将设置相同的选项卡。
但是,如果您没有重新加载数据,则禁用重新加载,这是问题的真正原因。
答案 2 :(得分:0)
除了@Webruster建议的方法。我还能够通过使用&#34;更新面板&#34;来解决问题。感谢大家的建议。