在C#,ASP.net中选择下拉列表后重置选项卡
在C#,ASP.net中选择下拉列表后重置选项卡,c#,jquery,asp.net,C#,Jquery,Asp.net,10 25 50 100 250 页码: 函数resetTabs(){ $(“#content>div”).hide();//隐藏所有内容 $(“#制表符a”).attr(“id”,”);//重置id的 } var myUrl=window.location.href//获取URL var myUrlTab=myUrl.substring(myUrl.indexOf(“#”);//对于localhost/tabs.html#tab2,myUrlTab=#tab2 var myUrlTab
10
25
50
100
250
页码:
函数resetTabs(){
$(“#content>div”).hide();//隐藏所有内容
$(“#制表符a”).attr(“id”,”);//重置id的
}
var myUrl=window.location.href//获取URL
var myUrlTab=myUrl.substring(myUrl.indexOf(“#”);//对于localhost/tabs.html#tab2,myUrlTab=#tab2
var myUrlTab name=myUrlTab.substring(0,4);//对于上面的示例,myUrlTabName=#tab
系统应用程序添加加载(选项卡);
(功能选项卡(){
$(“#content>div”).hide();//最初隐藏所有内容
$(“#tabs li:first a”).attr(“id”,“current”);//激活第一个选项卡
$(“#content>div:first”).fadeIn();//显示第一个选项卡内容
$(“#选项卡a”)。在(“单击”,功能(e){
e、 预防默认值();
if($(this).attr(“id”)==“current”){//当前选项卡的检测
返回
}
否则{
resetTabs();
$(this.attr(“id”,“current”);//激活此
$($(this.attr('name')).fadeIn();//显示当前选项卡的内容
}
});
对于(i=1;i将Jquery代码添加到Sys.Application.Add\u load(//此处为您的代码)
onDOM
ready
编辑2(已删除重置选项卡功能,并在添加加载中直接调用)
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
}
}
})()
$(文档).ready(函数(){
系统应用程序添加加载(函数(){
$(“#content>div”).hide();//隐藏所有内容
$(“#制表符a”).attr(“id”,”);//重置id的
$(“#content>div”).hide();//最初隐藏所有内容
$(“#tabs li:first a”).attr(“id”,“current”);//激活第一个选项卡
$(“#content>div:first”).fadeIn();//显示第一个选项卡内容
$(“#选项卡a”)。在(“单击”,功能(e){
e、 预防默认值();
if($(this).attr(“id”)==“current”){//当前选项卡的检测
返回
}
否则{
resetTabs();
$(this.attr(“id”,“current”);//激活此
$($(this.attr('name')).fadeIn();//显示当前选项卡的内容
}
});
对于(i=1;i当您从下拉列表中选择值时,您的页面回发(很可能是必需的)。现在回发会将您带到服务器端,核心问题是您没有告诉服务器您在第6个选项卡上
将选项卡id传递给服务器,以便回发返回时,它将检查选项卡id并将相同的选项卡设置为启用
但是,如果您没有重新加载数据,则禁用重新加载,这是问题的实际原因。除了@Webruster建议的方法之外,我还可以使用“更新面板”解决问题。谢谢大家的建议。您的页面正在对所选内容执行回发。这意味着页面将刷新并在布局中重新开始,因此您将丢失所选的选项卡。如果您希望通过回发来保持选项卡选择,我将创建一个隐藏字段,并且在选择选项卡时,在隐藏字段中保留其ID,然后n page load或post back让您的Jquery根据加载页面时的情况选择其选项卡,或者如果字段为空,则初始加载默认为选项卡1,并开始将其设置为选中选项卡。或者启用下拉选择Ajax,以便页面不会刷新。我正在尝试实现此选项。但它不起作用。您能否提供更多信息,如代码的哪一部分。谢谢。我刚刚按照您的建议编辑了代码。您可以在代码的jquery部分看到更改。@Raags某种程度上的意思是??如果可能,添加resetTabs()
函数添加到加载
好。我会试试。下拉列表工作正常,但我丢失了选项卡的功能。所有选项卡的内容都显示在一页上。如果它帮助您接受它作为答案。它可能对其他用户有用
</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
}
}
})()
<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>