Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ASP.NET
<!-- Home -->
      <li class="current"><a href="Home.aspx">Home</a>
      
      
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="userwelcome.aspx">My Page</asp:HyperLink></li>
      </li>  


i want to hide this hyperlink when the session["username"]==null,
and my this idea working fine but there is a problem when session is null then because it is with in
HTML
<li>hyperlink</li>

so it hides the My Page text from the Hyperlink but showing Blank Square box.(because hyperlink's text is not there when visibility is false)

i want to hide this blank Square box.
Any Idea?
Posted

I am not sure I get your problem well...
To hide the hyperlink you can just type:

C#
HyperLink1.Visible = !(session["username"]==null);


If you have rendering issue it is probalby because you have 2 closing "li" for only one opening.
 
Share this answer
 
v2
Hi
You can use a runat="server" attribute inside li and hide that also when you hide the link button. Hope that helps you.
 
Share this answer
 
Comments
Surendra0x2 1-Oct-12 6:22am    
how to hide Li tag as we hide linkbutton like linkbutton.visible=false;
but there is no li server tag present ...
Surendra0x2 1-Oct-12 6:42am    
i got the solution Buddy u also helped me
<ul runat="server" id="hide">
<li> <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="userwelcome.aspx">My Page</li></ul>

i added runat="server" and id to my <ul> tag then set the visibility false when session is null .
if (Session["email"] == null)
{

HyperLink1.Visible = false;
hide.Visible = false;


}
else if (Session["email"] != null)
{


HyperLink1.Visible = true;
hide.Visible = true;


}
TanvirRaihan 1-Oct-12 8:57am    
could also try for individual li...
Example
<ul>
<li runat="server" id="liHide">dfdfddfdf </li>
</ul>
Surendra0x2 1-Oct-12 13:25pm    
yeah...Buddy Thanks :)
ASP.NET
<ul  runat="server" id="hide">
         <li> <asp:hyperlink id="HyperLink1" runat="server" navigateurl="userwelcome.aspx" xmlns:asp="#unknown">My Page</asp:hyperlink></li></ul>


and in codebehind i wrote
C#
if (Session["email"] == null)
        {

           HyperLink1.Visible = false;
            hide.Visible = false;
            

        }
        else if (Session["email"] != null)
        {

           
            HyperLink1.Visible = true;
            hide.Visible = true;


        }


I Added
ASP.NET
Runat="Server"
and
HTML
id="hide"
to
HTML
<ul>
tag then set the visibility false when session is null else true :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900