Comparing the previously selected node with the currently selected node in an ASP.NET treeview

I am looking to implement a comparison between the last selected node and the currently selected node on a tree view using JavaScript.

Can anyone provide me with some code snippets to help me compare the previous selection with the current selection on the tree view?

If both node selections are the same, I would like to deselect the node.

Thank you in advance for your assistance.

I have successfully resolved this issue with the following server-side code:

 protected void TreeView1_PreRender(object sender, EventArgs e)
    {
        if (TreeView1.SelectedNode != null)
        {
            if (!string.IsNullOrEmpty(ADUtility.treenodevalue))
            {
                if (ADUtility.treenodevalue == TreeView1.SelectedNode.ValuePath)
                {
                    TreeView1.SelectedNode.Selected = false;

                }
                else
                {
                    ADUtility.treenodevalue = TreeView1.SelectedNode.ValuePath;
                }
            }
            else
            {
                ADUtility.treenodevalue = TreeView1.SelectedNode.ValuePath;
            }
        }
    }

Answer №1

Providing a Pseudo code snippet for your reference, you can customize it as needed: Define two global variables, CurrentselectedNode and PreviousselectedNode, and create an ArrayList to store Nodes.

ArrayList<Object> nodeCollection;
var PreviousselectedNode;
var CurrentselectedNode;

if(nodeCollection.Current != null)
{
    PreviousselectedNode= nodeCollection.Current;
    var tempselectedItem = Products_Data.selectedNodeID.value;
    var CurrentselectedNode = Document.getElementById(tempselectedItem);

// Perform actions on the current and previous nodes as required

    nodeCollection.Add(tempselectedNode);
}
else
{
    var tempselectedItem = Products_Data.selectedNodeID.value;
    var tempselectedNode = Document.getElementById(tempselectedItem);
    nodeCollection.Add(tempselectedNode);
}

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

How to dynamically load bootstrap-multiselect within a loop in a vueJs application

I am attempting to dynamically load bootstrap-multiselect in a loop using VueJs. My desired implementation looks something like this: <div class="col-xs-6 col-sm-4 mb-1" v-for="params in param"> <select class="mult" multiple="multiple"> ...

Ways to Manage modals responses as services in AngularJS

I am a beginner in the world of JavaScript and AngularJS. I am fascinated by some of the concepts within JS, like trying to create a modal service using the example I found online. I am eager to delve deeper into what exactly is happening under the hood, e ...

The issue with 'this' not resolving correctly within a prototype method is causing unexpected behavior in the context of inheritance

I've created a constructor that extends a module in node.js called (https://github.com/fluxxu/evalidator). Within this extended constructor, I've defined two additional methods in the prototype, with **method B** calling method A using the ' ...

The connection to the firebase callback

Upon examining this function, it appears that there may be an issue with a null value causing the error message to display: (node:16232) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'groupPages' of null async setTriggers() { ...

Loading bar for AngularJS material framework

Is there a way to integrate https://material.angularjs.org/latest/demo/progressLinear into my website so that it shows progress when a new view is loading? I'm trying to figure out how to obtain the value of the current page being loaded. Any suggest ...

What is the best way to upload this HTML file to create my own visual representation?

Feeling a bit unsure about which way to go for this problem, I don't have many options at the moment. Lately, I've been diving into Deep Learning and I'm interested in experimenting with Stanford's CS231N's Convolutional Neural Ne ...

Prevent identical values from being added repeatedly to a table while updating in real-time

Currently, I am facing an issue while running through a loop to extract values from an array. When I add a second value, it duplicates both the new and previous values in the table. For example, adding a row with value 488 works fine: <tr class="exe"& ...

The content inside a Textbox cannot be clicked on. I am seeking help with implementing JavaScript to enable it to be

As a newcomer in the world of programming, I am sharing a snippet of my JavaScript and HTML code with you. I am facing an issue where I want to enable users to start typing in a text box upon clicking on the text "User Name", without deleting any existing ...

The Document.querySelector() method is not displaying every element

As a beginner, I am currently exploring the world of relative CSS selectors and JSPath for my automation scripts. During my journey, I noticed that there are differences in the return statements between these two methods. Below is an example demonstrating ...

What is the best way to target and manipulate the transform property of multiple div elements in JavaScript?

Looking at this code snippet, my goal is to have all the boxes rotate 180deg with a single click, without needing to apply different ID names: function rotateAllBoxes() { var boxes = document.getElementsByClassName("box"); for (var i = 0; i < box ...

Unwrapping a packed struct from c# in Node.js: A step-by-step guide

We are currently utilizing a customized source library developed in cpp, with a binding in C# that includes various structs designed for extracting data from the cpp library into c# structs. However, I am facing a challenge in figuring out how to unpack th ...

Gathering information from various web pages simultaneously without the need to manually navigate through each page using a webdriver

I'm new to the world of web scraping and I've successfully developed a program that allows me to extract specific, dynamic data by utilizing the selenium web driver. My current project involves scraping data from a FAQ page in order to gather in ...

Ways of transferring session variables from one page to another?

Initially, I am working with multiple webpages in express. After saving a variable into a session during a post request, the page redirects to another page. However, when trying to access the variable on that new page, it is returned as "Undefined." Upon f ...

Convert a single object into a JSON string representation on each line

Can you convert the following data into the desired format through stringification? Data: let result = JSON.stringify([ { "Color": "Red", "Type":"Fast" }, { "Color": "Blue&quo ...

Enabling block scrolling on a parent element using jscrollpane functionality

Is it possible to set up a jscrollpane so that the parent pane doesn't scroll when the child scroll has reached its bottom? Currently, when the child scrolling reaches the bottom, the parent also scrolls. I would like the parent to only scroll when th ...

Looking to $post the text strings within select boxes, rather than just their values

Looking to extract the text of select boxes, rather than just their values. HTML : <select name="one" id="one"> <option value="0">Select *</option> <option value="3000">Plan A</option> <option value="6000"> ...

NextJs getStaticPaths function is failing to render the correct page, resulting in a 404 error message being displayed

Hey there, I'm in a bit of a pickle as I've never used 'getStaticPaths' before and it's crucial for my current project! I followed the example code from NextJs's documentation on 'getStaticPaths', but when I try to ...

Sending a JavaScript variable to a Flask url_for function

There is an endpoint that requires a value in the URL and then generates content to be displayed within a specific div. I'm trying to construct the URL using url_for with a JavaScript variable, but it seems that $variable1 is being treated as a string ...

Dialog in Angular Material refuses to close even after calling the dialog.close() function

I've been struggling with this issue for a while, hoping someone can assist. In my Angular project, I have a login component with a dialog that opens a new popup window. Upon successful login, this window closes and triggers the following function: l ...

The Angular custom modal service is malfunctioning as the component is not getting the necessary updates

As I develop a service in Angular to display components inside a modal, I have encountered an issue. After injecting the component content into the modal and adding it to the page's HTML, the functionality within the component seems to be affected. F ...