在.aspx页面中,我有两个标签:Acct和HR。
在代码背后我有这些条件:
active
)案例#1和案例#2正常运作。
但是情况#3(需要显示选项卡和导航以及所有内容),我遇到了问题:导航(li
)工作正常(当我点击它时,它显示正确的CSS) ,但是当我舔到人力资源li
以下是案例#3的图片,所以在我设置的page_load()代码中,它首先显示了Acct选项卡:
当我切换到HR选项卡时,导航菜单已更改,但内容选项卡保持不变:
反之亦然,如果我设置 HR 是active
,那么当我切换到帐户时,它将不显示Acct标签内容,继续显示HR的标签内容
以下是标记代码和C#代码:
<div class="tabbable tabbable-custom">
<ul class="nav nav-tabs" style="margin-bottom: 0px">
<li style="width: 50%" id="liAcct" runat="server"><a class="no-margin" href="#tabAcct" data-toggle="tab">
<h3 class="text-center no-margin bold text-success">ACCT</h3>
</a></li>
<li style="width: 50%" id="liHR" runat="server"><a class="no-margin" href="#tabHR" data-toggle="tab">
<h3 class="text-center no-margin bold text-primary" style="margin-left: 20px !important">HR</h3>
</a></li>
</ul>
<div class="tab-content" style="border: 1px solid #ddd; border-top: none; padding: 5px">
<!-- BEGIN ACCT TAB -->
<div class="tab-pane" id="tabAcct" runat="server">
<asp:Panel ID="panelAcct" runat="server">
<h1>This is Acct content</h1>
</asp:Panel>
</div>
<!-- END TAB -->
<!-- BEGIN HR TAB -->
<div class="tab-pane" id="tabHR" runat="server">
<asp:Panel ID="panelHR" runat="server">
<h1>This is HR content</h1>
</asp:Panel>
</div>
<!-- END TAB -->
</div>
</div>
在page_load()中:
if (!IsPostBack)
{
Page.Title = "Page";
string managerEmail = HttpContext.Current.User.Identity.Name.ToLower();
if (requestDAL.GetManagerLevel_byEmail(managerEmail) <= 1)
{
// Shows HR tab
liHR.Attributes["class"] = "active";
tabHR.Attributes["class"] = "tab-pane active";
// Hide Acct tab
liAcct.Visible = false;
liAcct.Visible = false;
panelAcct.Visible = false;
}
else if (requestDAL.GetManagerLevel_byEmail(managerEmail) == 2)
{
// Shows ACCT tab
liAcct.Attributes["class"] = "active";
tabAcct.Attributes["class"] = "tab-pane active";
// Hide HR tab
liHR.Visible = false;
liHR.Visible = false;
panelHR.Visible = false;
}
else
{
liAcct.Attributes["class"] = "active";
tabAcct.Attributes["class"] = "tab-pane active";
}
}
答案 0 :(得分:2)
Asp.net更改了客户端的所有服务器端控件ID。您只需使用ClientID来获取正确的标记ID:
<a class="no-margin" href="#<%= tabAcct.ClientID %>" data-toggle="tab">
<a class="no-margin" href="#<%= tabHR.ClientID %>" data-toggle="tab">