1

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!

1
  • 1
    No you can't. And if you find a way to do so i would consider the browser you did it in as broken and would search for a replacement. If you want to hide something from the user don't send it to the client.
    – Ralf
    Commented Oct 19, 2020 at 11:54

1 Answer 1

0

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;
6
  • Okay. runat="server" AND Visible="false" is going not delivered to the Client?
    – comidos
    Commented Oct 19, 2020 at 12:43
  • @comidos yes is not going to render it, try it
    – Aristos
    Commented Oct 19, 2020 at 12:44
  • what do you mean with "warp your content"?
    – comidos
    Commented Oct 19, 2020 at 12:44
  • that is not so easy. I use Controls from DevExpress with embedded buttons for example, which i can only hide via Visisble=false in CodeBehind but not set runat="server"
    – comidos
    Commented Oct 19, 2020 at 12:50
  • can you explain with a <li>-element for example?
    – comidos
    Commented Oct 19, 2020 at 12:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.