Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7818361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:33:09+00:00 2026-06-02T06:33:09+00:00

I have a menu item Login that navigates to the login page. When a

  • 0

I have a menu item “Login” that navigates to the login page. When a user is logged in, I have the text for that menu item changing to “Logout”. When clicked, I want it to go back to clear the session, go to the login page, and for the text to change back to “Login”. And this works…kinda. The problem I’m having is that I don’t know how to call a function when clicking on a menu item, so when the user clicks “Logout” the login page loads and the session is cleared when the page loads, but since it’s not cleared before the page loads, it still appears that there is a session (username still appears, and menu item text isn’t changed). How can I set it so that the session is cleared in “Logout” is clicked instead of when the login page loads?

Here’s my menu code:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LeftSideMenu.ascx.cs"   Inherits="EVMAnywhereWeb.Controls.LeftSideMenu" %>

<div id="leftSideMenu">
<asp:menu ID="menu1" runat="server" Orientation="Vertical" RenderingMode="List">
<StaticMenuItemStyle VerticalPadding="5" />
<DynamicMenuItemStyle VerticalPadding="5" />
<Items>
    <asp:menuitem navigateurl="~/Login.aspx" Text="Login" Value="Login"></asp:menuitem>
    <asp:menuitem navigateurl="~/Register.aspx" Text="Register" Value="Register"></asp:menuitem>
    <asp:menuitem navigateurl="~/Projects.aspx" Text="Projects" Value="Projects"></asp:menuitem>
    <asp:menuitem navigateurl="~/Dictionary.aspx" Text="Dictionary" Value="Dictionary"></asp:menuitem>
 </Items>   
</asp:menu>
</div>

Here’s the code I use to change the text (in the code-behind):

 protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["SessionUserName"] != null)
        {
            menu1.Items[0].Text = "Logout";
            menu1.Items[1].Text = "My Account";

        }
    }

And in the login page code-behind, I have this to clear the session:

 protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["SessionUserName"] != null)
        {
            Session.Abandon();
            Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetNoStore();

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T06:33:11+00:00Added an answer on June 2, 2026 at 6:33 am

    Call your code to clear the session in OnInit instead of Page_Load.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Menu page. If a user selects an Menu Item it opens
I have a menu, when the user clicks on any menu item, I want
I have a menu item to which I add another item. Now I want
I have asp.net Menu Item <asp:MenuItem NavigateUrl= Text=Download Value=Download/> . When this item gets
i have menu structure like below, <ul> <li class=menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-1406
I have class that extends Activity. That has a Logout menu options. When I
I have dropdown menu item (pin this site) that i need to hide it
I have a menu item Home in my main menu AND in my top
I have a menu item which has children menu items. When one of the
I've defined a custom content type - news. I also have a menu item

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.