How to dynamically unhide a anchor tag that I have hid using "display:none" in my asp.net project

Adithyan 0 Reputation points
2023-05-12T05:27:34.0066667+00:00

This is the code I have
<div class="dropdown" id="drp" runat="server">

<div class="tab"> tab</div>

<div class="drpdown-content" style="top:20px">

<a href="link" id="Hide">application</a>

<a href="link">application1</a>

<a href="link" >application2</a>

<a href="link">application3</a>

</div>

<style>

#Hide{

display:none;

}

</style>

with this I am able to hide the anchor tag. But I have a specific condition when I have to make the anchor tag visible. How would you do that?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,362 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 27,721 Reputation points Microsoft Vendor
    2023-05-12T07:33:41.3666667+00:00

    Hi @Adithyan,

    You can always declare a local variable at the beginning of the View,and then just use it in your tag:

    The following test is hidden when a<0, otherwise it appears.

    @{    
         var a = 4;
         var style = (a < 0) ? "display:none" : "";
    }
    
    <div class="dropdown" id="drp" runat="server">
    
        <div class="tab"> tab</div>
    
        <div class="drpdown-content" style="top:20px">
    
            <a href="link" id="Hide" style="@style">application</a>
    
            <a href="link">application1</a>
    
            <a href="link">application2</a>
    
            <a href="link">application3</a>
    
        </div>
    </div>
    

    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments