Take the 2-minute tour ×

I would like to use a control which will contain links to other pages and put all these links inside a control (EG table) so that I will be able to hide it with code (show only for administrator)

Other than a table which control should I use? Should I use a panel or something else?

share|improve this question
This sounds extremely easy to bypass... –  mikeTheLiar Dec 26 '12 at 15:07
Rather than hiding don't create when the user has no access to it. –  Șhȇkhaṝ Dec 26 '12 at 15:11

5 Answers 5

up vote 2 down vote accepted

If you want to hide some link use simple Hyperlink control and set visible property only for administrators. You can use Repeater control to render table and and in ItemTemplate set Hyperlink.

Otherwise you can use Placeholder and place table in it, and set visible property of Placeholder, Placehodler wont render anything.

And after all you can use that same Table, add ID and runat="server" attributes and set visible from Code behind.

for example :

<table ID="myTable" runat="server">

and then in code hide whole table :

protected void Page_Load(object sender, EventArgs e)
  myTable.Visible = false;
share|improve this answer
Actually he can use any server running container aka Control, just set the property as you have said. –  IamStalker Dec 26 '12 at 15:07
oh, I was thinking that he want to disable some links –  Antonio Bakula Dec 26 '12 at 15:09

I would use a <asp:PlaceHolder because it is just a placeholder.. and has no other semnatic value like table,panel or this things..

share|improve this answer

Depends on your goals, as Antonio Bakula said, you can go through and set each individual link as non-visible.

Or if there are a lot of them, throw them in a panel that you can switch on and off wholesale.

share|improve this answer

You can use a panel to insert all your other controls in it (hyperlinks, buttons...etc) and in your code you can show and hide your panel and all what's inside by calling

share|improve this answer

A panel is a good choice.

An <asp:Panel /> is rendered in HTML as a <div>. If you aren't familiar with HTML, a <div> is just a box, and you can put anything (including a <table>) inside of one. For example, each answer on StackOverflow is shown inside of a <div>.

If you set Visible="false", then the entire <div> will be removed from your HTML output, even though it exists on the .aspx page. Basically, you can very effectively hide the links from non-administrators using this approach.

However, this is stil not very secure. It is very common for malicious users to attempt to find Administrator links just by guessing them (e.g.: /admin/default.aspx, /admin/admin.aspx, etc...). You should use roles to prevent users from accessing your Admin links. Roles prevent certain types of users (e.g.: Users who haven't logged in, or non-admin users) from even visiting these pages. Instead of seeing the page, the users will be shown an error message instead.

share|improve this answer

Your Answer


