Hide controls in ascx without access to code behind

I have a website which is written in VB.NET. I do not have access to code behind and only have access aspx/ascx pages. I have some controls like this in my ascx file.

<a href="../account/loginI2.aspx" runat="server"><img src="../css/icons/login.svg" /></a>

I want to make them visible based on if user is logged in or not logged in. I remember it is possible to put the code in design files but I do not remember the syntax in VB.NET and make it visible/unvisible for these controls.

1 answer

  • answered 2018-03-13 20:48 VDWWD

    If you do not need to access that link in code behind, which would seem to be the case, you can construct the html as a ternary operator. That way you avoid binding expressions.

    <%= Request.IsAuthenticated ? "<a href=\"../account/loginI2.aspx\">Login</a>" : "" %>

    Or as an inline if statement

    <% if (Request.IsAuthenticated == false)  { %>
      <a href="../account/loginI2.aspx">Login</a>
    <% } %>

    VB Example

    <% Dim IsAuth As String = IIf(Request.IsAuthenticated = False, "<a href=""../account/loginI2.aspx\"">Login</a>", "") %>
    <%= IsAuth %>