Click here to Skip to main content
16,014,294 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I'm working on a school project. I'm able to login user successfully who registered. But when he/she loged-in how can I hide Login and Register page link. I'm using css and <ul> for them. I want to hide those links and show there a SignOut link. And after sign-out how can I show them again. I'm using Session["id"] to check the user authentication not the FormAuth.
Here is the coding of my links on MasterPage.


XML
<td id="tabs2" style="width:190px">
                <ul id="logreg">
                            <li><a href="Login.aspx" ><span>LogIn</span></a></li>
                            <li><a href="Registration.aspx"><span>Register</span></a>
                            </li>
                            </ul>
                </td>


I tried with this code but getting error.

XML
<li id="liLogin" runat="server" visible='<%= (Session["id"] == null) %>' ><a href="Login.aspx"><span>LogIn</span></a></li>
<li id="liReg" runat="server" visible='<%= (Session["id"] == null) %>' ><a href="Registration.aspx"><span>Register</span></a></li>
<li id="liSignout" runat="server" visible='<%= (Session["id"] != null) %>' ><a href="Signout.aspx"><span>Signout</span></a></li>


Error

Cannot create an object of type 'System.Boolean' from its string representation '<%= (Session["id"] == null) %>' for the 'Visible' property.
Posted
Updated 31-Aug-20 0:50am

1 solution

Sorry if I fail to understand the essence of the problem, but to me, it looks like an artificial one. You have a form with authentication data, post it using "POST" method, and, on successful authentication, why do you think you should reload the same very page? You can go out off this page and send some other pages in response, using the form attribute action. On the other pages, you can only have "Logout", no need to have authentication form at all, until session timeout or other cases of closed session.

Well, on more complex site (look at the top of any page of CodeProject) you really might need to permanently keep login/logout part with the form and show/hide and/or enable/disable some elements, but why this can be a problem?

After all, if you need to hide a control, you can use and modify visibility VSS property. Please see the description of the property, pay attention for the JavaScript use: http://www.w3schools.com/cssref/pr_class_visibility.asp[^].

—SA
 
Share this answer
 

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