Enabling LinkButton in Asp.net after a delay of 10 seconds: A Step-by-

After clicking on the LinkButton lbUpVoteUndo, I need it to be disabled for a set period of time, such as 10 seconds. I attempted to achieve this using c# code-behind but now I'm curious if there is an alternative method to accomplish the same task.

protected void lbUpVoteUndo_Click(object sender, EventArgs e)
{
    lbUpVoteUndo.Enabled = false;

    if(/* verifying the duration of 10 seconds */)
    {
        lbUpVoteUndo.Enabled = true;
    }
}

Answer №1

To achieve this functionality, JavaScript can be utilized effectively. The following snippet of code consists of two lines that will enable you to accomplish the task:

function DisableFor10Seconds() {
      document.getElementById("<% lbUpVoteUndo.ClientID %>").disabled = true;
      setTimeout(function(){document.getElementById("<% lbUpVoteUndo.ClientID %>").disabled = false;},10000);
}

Although it has been some time since I delved into .NET webforms, based on my recollection, you could implement something like the following in your control:

<asp:LinkButton ID="lbUpVoteUndo" OnClientClick="Disablefor10Seconds();" />

It is worth mentioning that 10 seconds might seem like a substantial duration for users to wait. Consider if the user were to refresh the page, the button would regain its functionality after the specified time period. If you wish to maintain the disabled state for the button regardless of any actions taken by the user, storing a flag in Session or Cache and subsequently updating a client-side element with a timer could be a more suitable approach.

Answer №2

Utilize a javascript function -

To implement in HTML, insert the following code within your button control -

UseSubmitBehavior="false" OnClientClick="this.disabled='true'; this.value='Please wait...';"

In .CS code file, Include this snippet in your button click event -

System.Threading.Thread.Sleep(10000);

Appreciate it :)

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

Smooth-scroll plugin does not activate active state (due to JS modification)

I'm currently facing an issue with a script that handles smooth scrolling and the active state on my main navigation. The plugin in question can be found at: It's important to note that the navigation bar is fixed and therefore has no height. T ...

Determine the closest parent using jQuery

When using jQuery, the closest function can be called to locate the nearest parent element. For instance, if there is an a within a li within a ul within a td within a table, determining whether the ul parent is closer than the table parent may not always ...

Having trouble accessing the card number, expiration date, and CVC in vue using Stripe

Although I am aware that Stripe securely stores all information and there is no need for me to store it on my end, I have a specific requirement. When a user begins typing in the input area, I want to capture and access the card number, expiry date, and ...

Ensure the website is able to adjust its size when the top banner increases in size

On my website, there is a top banner containing contact information that expands when clicked. However, the expanded div overlaps the site content. Is there a way to make the site scale with the expanded div so that the top of the site starts below it? I ...

Guide on adding the contents of non-empty <td> tags using Javascript or JQuery

My goal is to calculate the total sum of all the HTML content within <td> elements with the attribute name='gross_val'. Here are the <td> elements I am working with: <tr><td name="gross_val" align="right" title="gross_val1" ...

Using Vuetify to display text fields in a single row

Check out this Vue component template (View it on CODEPEN): <div class="some-class"> <v-form > <v-container @click="someMethod()"> <v-row> <v-col cols="3" sm="3" v-for="p in placeholders" ...

Making a POST request with ajax in Django

I encountered some difficulties while attempting to send a POST request using ajax in Django. I have searched various resources, but have not yet found a solution. Below is the javascript code that I am using, following this guide: $.ajax({ url: &apo ...

The Angular modal service is failing to show up on the screen

I am having trouble implementing the angular modal service in my web application. When I click on the button, the modal does not appear. Can someone help me figure out what I am doing wrong? Builder View <div ng-controller="BuilderController as vm"> ...

Can you provide me with the ConnectionString necessary to establish an OdbcConnection for an access mdb file?

Having trouble connecting from C# to an Access MDB file using Odbc. Attempting to execute the following code: OdbcConnection con = new OdbcConnection( "Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\temp\\test.mdb;"); An except ...

For handling the onSubmit event, utilize both axios and axios-mock-adapter

I am attempting to utilize both axios and axios-mock-adapter in a single location to consolidate multiple mocks, then export the axios instance for use elsewhere: axios.js import axios from 'axios'; let api = axios.create({ baseURL: 'h ...

Modifying form data when submitting a form

Is there a common or widely-used method for modifying or adding form values before they are serialized and sent to the server upon form submission? I'm looking for a way to change or add these values without having to recreate them. I've come ac ...

Developing dynamic checkbox components using jQuery - unusual behavior in Internet Explorer

I am dynamically creating checkbox elements using jQuery and appending them to a specified node as shown below var topics = ['All','Cat1','Cat2']; var topicContainer = $('ul#someElementId'); $.each( topics, functio ...

What steps can be taken to address the issue of two components loading simultaneously?

While implementing page transitions with react-router-dom and react-spring's useTransitions, I encountered some bugs despite the transition animation working well. I believe CSS might help resolve these issues, but I am unsure about the exact approach ...

Passing HTML form variables to the controller in C# .NET Core

I'm struggling with passing a variable from an HTML form to a controller in my .NET Core project. The variable I pass to the controller is then used in a method call within an interface. Here's my data model for the form: public class JourneyFor ...

How do webpack imports behave within a ReactJS project?

In my ReactJS project, I have utilized various 3rd party libraries such as lodash, d3, and more. Interestingly, I recently discovered that I did not explicitly write imports like import d3 from 'd3' or import _ from 'lodash' in all of ...

Executing a script in the browser console automatically upon clicking a link can be achieved using Python

I am interested in executing JavaScript in my browser's DevTools console. Currently, I have managed to open a specific website through it. Is there a way to achieve this using Python? Here is the code I am currently using: url = 'http://some-we ...

Using regular expressions in Javascript to extract decimal numbers from a string for mathematical operations

I'm currently working on a Vue method where I extract information from a WordPress database. The data retrieved sometimes contains unnecessary text that I want to filter out. Using the prodInfo variable, the input data looks something like this: 2,5k ...

What is an alternative way to rewrite this regular expression without relying on the deprecated API?

My JavaScript code uses a regular expression, myRegexp, to match numbers in a string: var myRegexp = new RegExp('[0-9]+'); The code then extracts numbers from the string and returns an array: var string = '123:456'; var nums = []; wh ...

CSS styles are missing in ASP.Net MVC4 while debugging in Visual Studio 2012

While troubleshooting my website, I noticed that the CSS is not displaying. I am encountering an Error 500 on the Site.css file when inspecting it in Firefox. My _Layout.cshtml is configured to utilize the CSS files. @Styles.Render("~/Content/css") I h ...

Troubles Arising from Casting MdiChildren

I am facing a challenge with casting when dealing with MdiChildren. The following code snippet works fine: MyForm mf = (MyForm)this.ActiveMdiChild; However, the code below does not work as expected: MyForm[] mfs = (MyForm[])this.MdiChildren; Although ...