问题
In the following master.cs code:
public partial class Default : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
BasePage page = (BasePage)Page;
if (page.CurrentUser != null)
{
lblCurrentUser.Text = "<strong>" + page.CurrentUser.FullName + "</strong> - " + page.CurrentUser.CompanyName;
if ((Session["CCFUser"] != null) && (bool.Parse(Session["CCFUser"].ToString()) == true))
{
ctrlLinkBar.AddLink("Issues Management", "AllIssues.aspx");
}
else
{
if (true) ctrlLinkBar.AddLink("Home", "Default.aspx");
if (page.CurrentUser.Permissions.Issues()) ctrlLinkBar.AddLink("Issues Management", "AllIssues.aspx");
if (page.CurrentUser.Permissions.Time()) ctrlLinkBar.AddLink("Time Management", "TimeEntryForm.aspx");
if (page.CurrentUser.Permissions.Time()) ctrlLinkBar.AddLink("Time Filter", "TimeFilter.aspx");
if (page.CurrentUser.Permissions.SVN() && !(this.Page is _Default)) ctrlLinkBar.AddLink("SVN", "SVN.aspx");
if (true) ctrlLinkBar.AddLink("Profile", "ChangePassword.aspx");
if (page.CurrentUser.Permissions.Administration()) ctrlLinkBar.AddLink("Administration", "Administration.aspx");
}
}
else lnkLogout.Visible = false;
}
protected void lnkLogout_Click(object sender, EventArgs e)
{
Session.Abandon();
FormsAuthentication.SignOut();
Response.Redirect("Login.aspx");
}
}
i need to hide the link "Time Filter" so it doesnt appear on any of the web content forms. It doesnt have an id so i cannot caste it. How do I go about hiding it then?
回答1:
How about editing Master.cs to not add it, or only add it some of the time?
If that doesn't work, then you need to give us more context.
回答2:
Why not make ctrlLinkBar.AddLink take an Id in its constructor and create the link with an Id?
ctrlLinkBar.AddLink("TimeFilterId", "Time Filter", "TimeFilter.aspx");
Then, your content pages or whatever can find it and hide when needed.
回答3:
Am I missing something? Why not just delete the line?
if (page.CurrentUser.Permissions.Time())
ctrlLinkBar.AddLink("Time Filter", "TimeFilter.aspx");
来源:https://stackoverflow.com/questions/1705152/hiding-a-link-in-asp-net