Making Elements not possible to manipulate Visibility

I have a ASP-WebForm-Application with several User-Rights.

In CodeBehind I am hiding some Elements if the specific Rights aren’t given. But with F12 the User could manipulate the Code the get some Functionallity he isn’t allowed to.

Are there any possibilities to hide Elements from CodeBehind, that they aren’t make visible via Code-Manipulation? Something like destroying them completely in CodeBehind?

For example a Navigation based an List-Element, where I want to hide some Links:

<ul>
    <li>
       <a>link 1<a/>
    </li>
    <li>
       <a>link 2<a/>
    </li>
    <li>
       <a>link 3<a/> // Has to be hidden by some conditions
    </li>
 </ul>

Hope someone could help me!

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can use the asp:PlaceHolder or the asp:Panel and warp your content and make it visible or not.

Alternative you can add on the element the runat="server" Visible="false" and manipulate the visible.

Examples:

<ul>
    <li>
       <a>link 1<a/>
    </li>
    <li>
       <a>link 2<a/>
    </li>
    <li runat="server" id="pnlToHide">
       <a>link 3<a/> // Has to be hidden by some conditions
    </li>
 </ul>

or

<ul>
    <li>
       <a>link 1<a/>
    </li>
    <li>
       <a>link 2<a/>
    </li>
    <asp:PlaceHolder runat="server" ID="pnlToHide2">
    <li>
       <a>link 3<a/> // Has to be hidden by some conditions
    </li>
    </asp:PlaceHolder>
 </ul>

and on code behind

pnlToHide.Visible = false;


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x