How can I retrieve the name of the selected item in ASPXNAVBAR?

I am currently working with an ASPxNavbar and I am trying to achieve a functionality where the name of the NavBar item is displayed on a label every time the user clicks on it. I attempted to implement this feature using JavaScript, but unfortunately, my code does not seem to be working as expected.

Below is what I have tried so far:

<dx:ASPxLabel ID="ASPxLabel1" runat="server" Text="ASPxLabel">
        </dx:ASPxLabel>

<dx:ASPxNavBar ID="ASPxNavBar1" runat="server" EnableAnimation="True" Width="100%" 
        Theme="Material" AllowSelectItem="true" Target="contentUrlPane" ClientInstanceName="NavbarClick">
    <LinkStyle>
        <HoverFont Underline="False" />
    </LinkStyle>    
    <Border BorderWidth="0px" />
    <Paddings Padding="0px" />
    <GroupHeaderStyle HorizontalAlign="left" />

    <ItemStyle HorizontalAlign="left">
    <SelectedStyle BackColor="#404652 " ForeColor="#a2a2a2" />
    </ItemStyle>

<ClientSideEvents ItemClick="function NavbarClick(s, e) {
 ave  = e.item.name;
alert(ave)
document.getElementById('ASPxLabel1').innerHTML = ave;
}"/>
    <Groups>
    <dx:NavBarGroup Text="DASHBOARD" ></dx:NavBarGroup>
    <dx:NavBarGroup Text="Forms">
        <Items>
        <dx:NavBarItem Text="Cancel Memo" NavigateUrl="sample.aspx" Selected="True" Name = "Sample Title Here">
            <Image Height="18px" Url="Content/Images/1.png" Width="18px"  />
        </dx:NavBarItem>
        <dx:NavBarItem Text="Change Memo" NavigateUrl="Sample2.aspx" Name = "Another sample title here">
            <Image Height="18px" Url="Content/Images/2.png" Width="18px" />
        </dx:NavBarItem>
        </Items>
    </dx:NavBarGroup>
   </Groups>
   </dx:ASPxNavBar>

If anyone has any suggestions or solutions, I would greatly appreciate your help. Thank you!

Answer №1

Revise the assignment of the client-side ItemClick function for proper functionality:

<ClientSideEvents ItemClick="function(s, e) {
    itemName  = e.item.name;
    alert(itemName);
}"/>

Answer №2

private void HandleFiltersNavBarItemClick(object sender, NavBarItemEventArgs args)
{
   var itemValue = args.Item.Name;
   if (itemValue == "New")
   {
       // Add functionality for when the item value is "New"
   }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Single-use: Ajax event executes only on the first attempt

Upon entering incorrect details and running it, an error message pops up. However, when entering the correct details and clicking run again, the sign in button changes to "Connecting..." as expected but nothing else happens. $(document).ready(function() ...

Change in ReactJS URLs without causing the entire page to refresh when using BrowserRouter

After conducting extensive research and struggling for a solution for quite some time, it appears that I am facing an issue with my ReactJS project. As a beginner in ReactJS, I have developed a game (a quiz) with multiple levels where the component remains ...

Having trouble updating the DataTable with extra details retrieved from a new URL

I'm currently utilizing the DataTable plugin. After loading the DataTable, my aim is to reload the table, while keeping the existing content intact, and adding information gathered from a separate json file. However, I'm encountering an issue wh ...

Problem with redirecting when using HTTPS

I recently implemented an SSL Certificate and made changes to the web.config file. Here is the updated code: <system.webServer> <rewrite> <rules> <rule name="removed by me" stopProcessing="true"> ...

Angular $mdDialog allowing for multiple instances to be created

Working with modal tabs, I have a notification pop-up window that is always displayed to the user upon logging into my application. This pop-up contains all events that occurred while the user was offline. The issue arises when clicking on any object from ...

Creating links to other partials in AngularJS is a common task that can be achieved with

Creating a simple single page application with multiple partial pages in MVC5 has been a challenge. I have set up route configurations and controllers, but unfortunately, the links are not working as expected. When clicking on a link, instead of navigating ...

How can you toggle the visibility of a React component based on the user's device browser?

Seeking a solution to dynamically hide/show a component in a React/Nextjs/tailwind webapp based on the user's device type (e.g. desktop vs tablet vs mobile) due to differences in available keyboard keys (e.g. tab key not present on tablets and mobile ...

In PHP, a boolean variable will not display on the webpage when echoed

I am facing an issue with my PHP code where certain variables are not being echoed properly in the generated JavaScript. The code is designed to check if specific values are assigned in the $_GET global array and assign default values if they are not prese ...

Angular.js ng app is known for much more than just its controllers

I'm a beginner in Angular.js and facing an issue with setting up the controllers. When I try to run my code in the browser, I encounter an error 'uncaught referenceError: myappApp is not defined' for myappApp.controller('HomeController& ...

Using asynchronous functions in JavaScript to push an array does not function correctly

Trying to update the users array by pushing the dirs, but for some reason the dir property remains blank in the console.log statement after this. Any suggestions? I know I could use a synchronous function, but a friend mentioned that synchronous functions ...

Would it be considered improper to apply ID's to DOM elements for the purpose of automation, as it may transform their CSS classes into individual entities?

Just thinking about the best approach for Automation (such as Selenium). I've been advised against using IDs on elements, as it could result in JS errors (in case of duplicate IDs) and make CSS classes unique. While I see the point, not having IDs can ...

Issue with Inline JS not functioning correctly in Flask when integrated with Bootstrap 5

I'm developing a Flask web app with Bootstrap 5 and attempting to incorporate inline JS, but it's not functioning as expected. Specifically, I'm trying to use a simple alert() component, but nothing is displaying on the page. Interestingly ...

Corrupted PDF file after downloading on Chrome and Firefox

I've been using iTextSharp to generate PDF reports and store them on the web server where my application is hosted. Everything works perfectly when creating and accessing these files in the storage folder. It's important to note that I do not wan ...

Ways to extract data from an array containing nested objects

I have received data from an external source: [{ "mode": "CURR", "isin": "PLESLTN00010", "from": 451183, "to": null, "data": [{ "t": 1624265539, "p" ...

I am looking to consolidate my array of objects into a single object with distinct keys

Hey there! I'm looking to showcase the expenses for each category throughout the months of the year. Here's an example: {Month: "January", Food: 610, foodColor: "#063951", Others: 121, othersColor: "#C13018", …} Fo ...

How can one use jQuery to target elements that have names that are in an array format?

Is there a way to retrieve the values of these elements and send them as an array using ajax? <input type="checkbox" name="Broadcast[m]"/> Members <input type="checkbox" name="Broadcast[i]"/> IATA agencies <input type="checkbox" name="Bro ...

Expanding the Number of Arguments Sent to a Callback Function

I have a scenario where I am using a method that sends a POST request and then triggers a specific callback function to manage the response: myService.verify(id, verificationCallback); function verificationCallback(err, response) { ... } My query is two ...

Utilizing custom template tags with script tags for componentization within Django applications

Currently working on a Django project with multiple apps. One of the main apps serves as the base, housing global elements like CSS, JS, and custom template tags (referred to as CTTs). I'm interested in creating CTTs that contain HTML and script tags ...

How can I align a button right next to the table row data in HTML using Bootstrap?

Is there a way to add a button next to the table data in each row without a border? I attempted to create a new column for the button, but the border interferes with the design. I am using Bootstrap 4 for this project. Here is the HTML code: <div cl ...

Having trouble retrieving PHP variable values using JavaScript?

<div id="div01">01</div> <div id="div02">02</div> <img src="../img/logo.png" onclick="blueSky()"/> js function blueSky() { $.ajax({ type:'GET', url: 'test.php', success: function(respond) { document.ge ...