"Disabling a button in ASP.NET: A step-by-step guide

I'm facing an issue with my onclick code on an image, which is supposed to disable a button on my form. Here's what it looks like:

<img alt="" src="images/search-icon.png" width="16" height="16" style="display: inline;height:16px;cursor:pointer; width: 16px;" onclick="DisableButton('<%=btnSave.ClientID %>');" />

In my JavaScript, I have the following code:

function DisableButton(bSave) {
document.getElementById(bSave).attributes("Enabled", false);
}

The problem is that this code doesn't seem to work as expected. Whenever I click on the image, nothing happens. Could there be an error in my code? I'd appreciate any help or insights you can provide on this matter. Thank you in advance.

Answer №1

Remember to use 'disabled' attribute

document.getElementById(bSave).disabled = true;

Clarifying the difference between disable and disabled.

Answer №2

Check out this code :

 document.getElementById(btnSubmit).disabled = true;

Alternatively

document.getElementById('<%= submitButton.ClientID %>').disabled = true;

Answer №3

We recommend using the following code snippet for best results: Add this line to your script:

document.getElementById(bSave).disabled = true;

If you are utilizing jQuery, consider the following:

 $("#"bSave).prop("disabled",true);

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

Utilize AJAX to dynamically insert data into the database

I have created a JSP page that displays records, and now I am looking to include a dynamic link or button in the JSP that allows inserting data into the database without needing to refresh the page. This link should open a pop-up window with input fields ...

How do I pass data from an XML (or JSON) feed to my code behind using AJAX, allowing me to manipulate it effectively?

I am currently facing a challenge at work where the webserver (intranet) does not have internet access. In order to access data from another department, I have to rely on either an XML or JSON feed. Currently, I am using JavaScript to accomplish this task ...

Creating a button that redirects to an external link in CodeIgniter:

Hello everyone, I'm new here and I could really use some assistance with a problem. I am trying to link the button labeled 'lihat rincian' and each row of tables to redirect to an external link like Here's a snapshot of my datatables ...

Steps for adjusting the matMenuTriggerFor area so it only triggers when hovering over the arrow

Hello there! I'm currently working on adjusting the trigger area for opening the next menu panel. Right now, the next menu panel opens whenever I hover over either the title or the arrow. However, my goal is to have the menu open only when I hover ove ...

The duration from when the Ajax request is sent to when the response is received results in

Has anyone experienced strange results when measuring the time between sending and receiving an ajax request? Sometimes I get negative values. Can someone shed light on this peculiar behavior? var before = 0; var after = 0; $.ajax({ url: 'data.ph ...

Utilizing AJAX to dynamically load file references and embed iframes

Is the use of multiple iframes on a website impacting its loading speed? Also, regarding AJAX, let's say I have two JSP pages. The first one contains an AJAX call to the second JSP page. Both pages have JavaScript functions with the same name, let&apo ...

What could be causing these errors to occur when I use the fetch API?

Having trouble fetching the news API and getting this error message: TypeError: Cannot read properties of undefined (reading 'map'). Any suggestions on fixing this issue? Your help is much appreciated. import React, { Component } from 're ...

Unable to find any matches when conducting a search through Google Apps Script

After spending days analyzing the code, I am encountering an error that states "uncaught reference error: google is not defined." This issue seems to occur specifically in line 360. Curiously, when inspecting the original code editor, line 360 simply conta ...

How can you utilize jQuery to iterate through nested JSON and retrieve a specific matching index?

In the scenario where I have a nested JSON object like this: var library = { "Gold Rush": { "slides": ["Slide 1 Text","Slide 2 Text","Slide 3 Text","Slide 4 Text"], "bgs":["<img src='1.jpg' />","","<img src='2.j ...

Display the component once the useEffect has been updated in React JS

I am currently working on developing a TV app and I am in need of creating a QR Code with a randomly generated code. This code should either be fetched from localStorage or generated on-the-fly if localStorage is empty. However, I am encountering an issue ...

What is the best practice for utilizing Container.DataItem during data binding in ASP.NET? Are there any recommended resources or guidelines available?

Where can I find a comprehensive guide on data binding? I've come across various methods for data binding, but have yet to find a reliable reference. Does such a reference exist? I am aware of Bind and Eval, but how does Container.DataItem fit into t ...

Unable to access variables in the code behind

It seems like a simple issue at first glance. The challenge I am facing is that, despite creating a variable outside the DropDownList function to remember the user's selection before rebinding the list, it isn't accessible. The only workaround I ...

Utilizing React's useCallback with dependencies based on a function called within the callback

I've been working on a web application using React and came across an interesting implementation. Here's how it looks: const onAddNewAccount = useCallback(async () => { await refetch(); setOtherState((prev) => {...}); }, [refetch]); ...

Storing an array element in the cache with Vue.js when submitted through a form

I'm facing an issue with saving my input to the cache memory. I attempted to utilize the mounted method, but it's not performing as desired because it fails to retain the last input in memory; upon refreshing the page, the last input gets erased. ...

Whenever attempting to choose a rating, the MUI dialog continuously refreshes and resets the selected rating

I'm facing an issue with my MUI dialog where it keeps refreshing and resetting the selected rating every time I try to rate a movie. Any assistance on this matter would be highly appreciated. The RateWatchMovieDialog component is designed to display ...

Toggle divs by using a checkbox (Vue.js)

On my authentication page, I have implemented a checkbox that I want to use to toggle between Sign Up and Sign In forms. When the checkbox is clicked, it should display the Sign Up form, and when it's unchecked, it should show the Sign In form. I fou ...

Send input data to a script seamlessly without triggering a page reload

I'm facing an issue with sending form values to a script. My goal is to have the form values displayed on another part of the page when the user clicks a button. While I can achieve this using PHP or similar web scripting languages by sending the valu ...

The CORS policy has blocked access to the XMLHttpRequest at 'http://github/..file.json' due to its origin being 'null'

Recently, I attempted to request a JSON file hosted on GitHub (for example: ). What made my situation different from this question is that I was using pure javascript without jQuery to make the AJAX call. Here's the snippet from my index.js file: fu ...

The most efficient method of assigning array indexes to boolean values within an object

Struggling to determine the most efficient method of assigning array indices to an object with boolean values. Currently employing the following approach: let arr = [{t:1, te: "aa"}, {t:2, te: "aa"},{t:2, te: "aa"} ]; let obj ...

Unattended vuejs prototype arrays are not being monitored

During my Vue.js project, I attempted to create a global alert/notification system at the root level of the application. My approach involved pushing objects into an array and passing it to the component. In my app.vue file: <template> <div id ...