Controlling ASP/ASPX Label Visibility using JavaScript

I'm currently struggling with changing the visibility of a label when a button is clicked. The label should initially be hidden and then appear after the button is clicked.

My attempts using DevEx controls and the SetVisible() function have not been successful. When the label is first set to 'display: none' via CSS as I want, the function does not work.

I also tried using ASP labels and changing the display property on click, but once again nothing happened.

Styling

.dxd
{
    display: none;
}

JavaScript

<script type="text/javascript">
    function fncShow(s, e) {
        //show devex label
        lblTest.SetVisible(true);
        //show ASP label
        document.getElementById("lblASP").style.display = 'block';
    }
</script>

Body

<dx:ASPxButton runat="server" ID="btnTest" Text="Show" Width="100px" AutoPostBack="false">
    <ClientSideEvents Click="fncShow" />
</dx:ASPxButton>
<dx:ASPxLabel runat="server" ID="lblTest" Text="Test label" ClientInstanceName="lblTest" CssClass="dxd"></dx:ASPxLabel>
<asp:Label runat="server" ID="lblASP" Text="Test label 2" CssClass="dxd"></asp:Label>

I've tried several methods to make either control work without success. I now wonder if it's possible to have a label invisible initially, and how this can be achieved using both controls. As a newcomer to JS, I may be overlooking something, but all my attempts so far have failed. Any assistance would be greatly appreciated.

Answer №1

It turns out that a few minor adjustments were needed to bring everything together seamlessly.

In the DevEx control, there is a crucial property called ClientVisible. By setting this to false, you can hide the object initially and then use label.SetVisible() to toggle its visibility as needed.

Regarding the ASP label, Kevin's advice about setting the ClientIDMode to static was spot on. Once set to static, the ID remains constant, allowing for easy manipulation of the display and visibility properties using either

document.getElementByID().style.visiblity
or style.display.

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

What causes the intermittent failure of Selenium's Internet Explorer Driver in maintaining a consistent connection with the Web Driver Server?

After developing multiple Selenium tests for an AngularJS website, I encountered some challenges while trying to run the tests using Internet Explorer Driver in addition to Chrome and Firefox Drivers. Although most of the tests performed well in Internet E ...

The issue with React select right-to-left (RTL) functionality is that it

When using react select, I include isRtl as a prop like so: <Select onChange={handleChange} isRtl isMulti options={colourOptions} /> However, only the input receives the rtl direction style and not the options. How can I ensure that both the input a ...

Using $nin alongside $and in Mongoose

Implementing a filter for an admin user using mongoose operations. The user should be able to view all saved files except for those that are classified as draft files. However, the admin user should still have access to their own saved draft files. Code ...

Issue: ENOENT - The specified file or directory cannot be found while scanning in a discord bot

Recently, I decided to try my hand at creating discord bots even though I am new to it. After watching a tutorial and copying the code, I encountered an error that has me stumped: node:internal/fs/utils:347 throw err; ^ Error: ENOENT: no such ...

What steps do I need to take to execute a script that utilizes the mootools library within an asp.net environment

I've been working on a website that includes a mail form. I'm using the Mootools 1.4.3 library along with FormCheck 1.6.js. However, when I click the button, nothing happens except for the page refreshing. I really like this form and want to make ...

When Utilizing an async Task Method, DbContext is Properly Disposed

Currently, I have set up an async Task method to handle the IAuthenticationFilter interface. After logging in successfully, I can access an API with no issues when it has this attribute. However, if I revisit the API later on, an exception is thrown. publ ...

Retrieving information from an array and displaying it dynamically in Next.js

I've been diving into the Next.js framework lately and I've hit a roadblock when it comes to working with dynamic routes and fetching data from an array. Despite following the basics of Next.js, I'm still stuck. What am I looking for? I ne ...

Trouble brewing between Xamarin.iOS primary and secondary threads

Keeping it concise, here's the situation: When a button is pressed in the main UI thread, the following code is executed: MessageCenter.Init(); Among other tasks, the above method leads to: NS = NSTimer.CreateRepeatingScheduledTimer(TimeSpan.Pars ...

Update a JSON value using an MUI Switch element

I am currently developing a feature that involves toggling the state of an MUI switch based on API responses. The status of the Switch is determined by the Active field in the API response. If the JSON field is 1, the switch is turned on, and if it's ...

Working with JavaScript and making AJAX calls to interact with PHP backend

Having trouble with this code, it's not working as expected. I want to pass the value when I select an option from the dropdown menu, process the data using onChange event and display the value in the tag. <label for="headmark" class="lbl-ui selec ...

Showing information from a database in a grid using Windows Presentation Foundation and Windows Communication Foundation within a multi-tiered system

After successfully completing the tutorial found at this link, I attempted to adapt the same tutorial for use with WPF instead of Windows Forms. Despite keeping my code consistent (with the exception of the PresentationTier), I encountered difficulties in ...

Is it possible to utilize react for constructing a static HTML, CSS, and JavaScript document?

As a front end content developer, my main focus is on creating content assets. I typically use vscode to build my html, css, and js files, and then upload these static files to the content management system. However, this approach doesn't give me the ...

When utilizing backend Node.js with MongoDB, the patch request is unable to successfully update date type values

Using node.js, I have created the backend and integrated MongoDB for data persistence. However, I am facing an issue where I am unable to update the field of date type when making a patch request. Below is the code snippet for handling patch requests in t ...

Compel instantaneous XMLHttpRequest / Ajax without any prior notification

It's no secret that synchronous XMLHttpRequest has been deprecated due to its negative impact on user experience. The deprecation of Synchronous XMLHttpRequest on the main thread is a result of its adverse effects on end users' experience. For ...

What is the best way to transfer Jenkins information to an HTML page using JavaScript?

After following the instructions provided on the Jenkins website, I am now able to successfully log in to Jenkins using http://localhost:8080 When I access http://localhost:8080/api/json?pretty=true, I can retrieve a JSON response from my local server. Ho ...

``Is there a more SEO-friendly option instead of using an iframe?

I am looking for a solution to easily share my content with other websites without the issues I currently face. Presently, I use an iframe which poses two problems: <iframe width=“540”; height=“700” frameborder=“0” src=“http://www.energi ...

Using Mongoose, Express, and Node.js to send a server variable to an HTML page

I've encountered an issue while attempting to transfer a variable from my server.js file to HTML. Despite successfully passing the variable to another EJS file on a different route, I can't seem to display it within this specific EJS file. Strang ...

Caution: Exercise caution when rendering components in React due to unstable_flushDiscreteUpdates

Trying to utilize map to render a component, but encountering a warning: Warning: unstable_flushDiscreteUpdates: Cannot flush updates when React is already rendering. MyBooks.js import React, { useState, useEffect } from 'react'; import Action ...

Turbolinks not allowing the addition of JavaScript classes for background images

While trying to merge a front end html theme with my Laravel app, I encountered an issue with turbolinks that is preventing Javascript from appending div classes. This is resulting in background images only being displayed on page refresh. <div class= ...

Refresh the Parse.com User through a Stripe Webhook

Despite finding many Parse / Stripe questions on this platform, none have been able to assist me with my specific issue. In my mobile application, I have both free and paid features. A variable stored on the User class in Parse.com is used to check permis ...