---
title: "Set Session variable on menu item's click in asp.net"  
description: "Set Session variable on menu item's click in asp.net"  
author: "Mark Devid"  
published: 2014-10-08  
updated: 2014-10-08  
canonical: https://www.mindstick.com/forum/2339/set-session-variable-on-menu-item-s-click-in-asp-dot-net  
category: "asp.net"  
tags: ["c#", "asp.net", "asp.net mvc"]  
reading_time: 1 minute  

---

# Set Session variable on menu item's click in asp.net

ASP newbie here, in my [website](https://www.mindstick.com/articles/13110/why-copywriting-is-crucial-for-new-website-build) I need to set a [session variable](https://www.mindstick.com/forum/12804/how-to-set-a-asp-dropdownlist-selectedvalue-to-a-session-variable) when I [click](https://www.mindstick.com/articles/12423/social-login-magento-2-one-click-to-register-social) the [menu item](https://www.mindstick.com/forum/339/highlighting-the-menu-item)How can I achieve this, I have a [menu control](https://www.mindstick.com/interview/2227/what-does-the-orientation-property-do-in-a-menu-control) in my [master page](https://www.mindstick.com/blog/258/set-property-value-on-master-page-from-content-page) which has a [sitemap](https://www.mindstick.com/blog/301744/how-important-is-a-sitemap-for-the-indexing-of-your-website) file attached to it?\

```
<asp:Menu ID="mainMenu" runat="server" DataSourceID="siteMapSource"    StaticDisplayLevels="10" Width="150px">    <StaticSelectedStyle CssClass="menuNodeSelected" />    <LevelMenuItemStyles>        <asp:MenuItemStyle Font-Bold="True" Font-Underline="False" />    </LevelMenuItemStyles>    <StaticMenuItemStyle CssClass="menuNode" /></asp:Menu><asp:SiteMapDataSource ID="siteMapSource" runat="server" ShowStartingNode="False" />
```

## Replies

### Reply by Anonymous User

```
<asp:Menu ID="mainMenu" runat="server" DataSourceID="siteMapSource"    StaticDisplayLevels="10" Width="150px"    OnMenuItemClick="NavigationMenu_MenuItemClick">    <StaticSelectedStyle CssClass="menuNodeSelected" />    <LevelMenuItemStyles>        <asp:MenuItemStyle Font-Bold="True" Font-Underline="False" />    </LevelMenuItemStyles>    <StaticMenuItemStyle CssClass="menuNode" /></asp:Menu><asp:SiteMapDataSource ID="siteMapSource" runat="server" ShowStartingNode="False" />
```

You should set a method to be called on server side OnMenuItemClick, this will rise the event of menu click. That event is (in our case): NavigationMenu_MenuItemClick.

On Code-Behind you can do whatever you want when an menu item is selected.

```
void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e)        {            // Display the text of the menu item selected by the user.            Message.Text = "You selected " + e.Item.Text + ".";            Session["variable"] = e.Item.Text;        }
```


---

Original Source: https://www.mindstick.com/forum/2339/set-session-variable-on-menu-item-s-click-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
