unable to assign value to `visibility` or `display` properties

I am having an issue with a dropdownlist box in the datagrid that I need to hide or show. I can retrieve the element, but when I try to hide it, I encounter an error 'Unable to set property 'display' of undefined or null reference.' I have also attempted using visibility, but encountered a similar error. Can someone please provide guidance on how to achieve this? Thank you.

Here is my control:

<asp:dropdownList ID="dropID" runat="server" cssclass="selectColor w175 show"/>

The corresponding class in my style sheet:

.show   {
display: normal;
}    

.selectColor {
color: #333333; }       

.w175 { width:175px; }

This is my JavaScript function:

function NeedChange(id) {
 var dropID = document.getElementById(id);
  if (dropID!=undefined ){
    //dropID.style.visibility="hidden";
    dropID.style.display='none';
}
 }

Answer №1

Your current method faces a challenge because the ID dropID does not actually exist on the page, making it inaccessible to your JavaScript code. In asp.net, IDs for elements that display repetitive data (such as GridView, ListView, Repeater, etc.) are converted into a format like

ContentPane1_GridView1_DropDownList1_0
. As a result, in order to show or hide a specific DropDownList, you first need to determine the row number and then construct the full element ID using this pattern:

<script type="text/javascript">
    var myElement = "<%= GridView1.ClientID %>_dropID_" + rowNumber;
    // This will be transformed into something like ContentPane1_GridView1_dropID_24

    document.getElementById(myElement).style.display = "none";
</script>

The process of obtaining the row number can be complex and will vary based on the structure of your grid and the specific criteria for hiding the dropdown element.

Answer №2

Here is a solution that should be effective

function ModifyElement(identifier) {
var element = document.getElementById(identifier);
if (element !== undefined ){
//element.style.visibility="hidden";
$("#element").removeClass("show");
}
}

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 is the best way to retrieve information from nested JSON objects?

Currently, I am attempting to retrieve messages in Node.js using discord.js. { "627832600865800222": { //guild id "348832732647784460": { // author id "message": "hii hello" } } } let autho ...

What is the purpose of the .Class method in ng.core.component within ES5?

ng.core.Component({ selector:'myapp', template:'<h1>Hello World</h1>' }). Class( { constructor:function() } ); ...

Getting the value of text from a textbox inside a FormView within an ascx file can be accomplished by accessing it in the ascx.cs file

I am encountering an issue with retrieving the value from an asp: text box that is located in a FormView within an ascx file. Here is my code: <asp:FormView runat="server" ID="myFrmView"> <asp:TextBox runat="server" ID="txtBox1" size="20" Ma ...

Fluctuating Values in Array Distribution

I have a set of users and products that I need to distribute, for example: The number of values in the array can vary each time - it could be one value one time and three values another time. It is important that each user receives a unique product with ...

Stop ckeditor from triggering set callback when the text is modified by an external source

Currently, I am developing a Vue project that involves the use of ckeditor5 as a text editor. Pusher, a real-time API utilizing websockets, is used to broadcast events to other Pusher instances in real time. Learn more about Pusher here. Within the ckedit ...

Attempting to integrate a three.js OBJLoader within an HTML canvas

My issue is quite straightforward: I attempted to connect a three.js script with an HTML canvas, but I was unsuccessful and now I'm unsure how to proceed. Here is the code I have (I've already loaded the necessary scripts in the HTML head): wi ...

Generating an array by iterating through each object within an array of objects

I am working with a JSON structure and I need to separate it into two arrays. The first array should include all the values from the key "employee only" to "Annual OOP max / entire family" from each object in the JSON array. The second array should contain ...

Vuetify's v-badge showcasing an exceptionally large number in style

Encountering an issue with using v-badge and v-tab when dealing with large numbers in a v-badge. Managed to find a CSS workaround by setting width: auto; for adjusting the size of v-badge to accommodate huge numbers, but now facing an overlap with my v-ta ...

Guidelines for adjusting canvas dimensions based on parent div attributes

Trying to insert a p5.js canvas into a div using the divs width to control the canvas width, within a jekyll post. The markdown file includes a div positioned at the top of the post. <div id="myCanvas"</div> <script src="/js/p5Sketches/firstP ...

Interested in integrating Mockjax with QUnit for testing?

I recently came across this example in the Mockjax documentation: $.mockjax({ url: "/rest", data: function ( json ) { assert.deepEqual( JSON.parse(json), expected ); // QUnit example. return true; } }); However, I'm a bit confused abou ...

Creating a div that becomes fixed at the top of the page after scrolling down a certain distance is a great way to improve user experience on a

I am struggling to create a fixed navigation bar that sticks to the top of the page after scrolling 500px, but without using position: fixed. Despite trying various solutions, none seem to work due to the unique layout of my navigation bar. Strangely enoug ...

Ways to incorporate various styles on a mobile screen for a javascript-generated function

In my current project, I have implemented a JavaScript function that renders HTML within a module. function generateHTML(bankName) { let content = `<div class="bankName" style=""><strong style="font-size: 28px;font-wei ...

Cystoscape has ventured beyond the limits of the canvas border

I am trying to confine the objects within the cytoscape canvas so they do not move outside of the maximum width and height. However, when I drag the objects within the canvas, they go outside of the canvas border: https://i.sstatic.net/Su4PE.png Currentl ...

Learn the steps to designing a responsive class using Angular2's ngClass feature

Imagine a scenario where the object models in my cloud Array include a weight key: return [ { term: '1994', weight: 0 }, { term: '2017', weight: 0 }, { term: '89th', ...

Uncovering the Power of Shadow DOM within HTML

Lately, I've noticed a lot of buzz surrounding Shadow DOM. During a video I watched about the launch of Angular 2, the speaker kept mentioning Shadow DOM without much explanation. Can someone clarify what exactly Shadow DOM refers to? ...

Identifying the class name of SVGAnimatedString

While working on creating an SVG map, I encountered an issue where the functions triggered by hovering over 'g' elements were not functioning as expected. In order to troubleshoot this problem, I decided to check for any issues with the class nam ...

Organize my JavaScript code by implementing a function

I have repetitive javascript code that I would like to refactor into a function. Is there a way to streamline this process and make the code more efficient? The two functions I want to consolidate are: bright() $(VARIABLE).find('.info').fadeTo ...

What is the best way to transform a string into React components that can be displayed on the screen?

Stored in my database are strings that contain partial HTML content, as shown below: “Intro<br /><br />Paragraph 1<br /><br />Paragraph 2” If I want to display this string within a new <p> element, what is a straightforwa ...

Facilitate the exchange of updates and information between the server and client

Seeking advice on how to report progress to the client during a lengthy import process in a controller action. The task involves uploading an excel file into a database and can take several minutes to complete. I understand that AJAX should be used for thi ...

Initial value preselected for radio button

Is there a way to ensure that the Default radio button selected in the following code is always "Period"? Currently, when the page loads, none of the radio buttons are selected. <tr> <th valign="top" align="left"> Scope ...