1

I'm trying to implement some sort of solution to the 'double submit' problem that occurs when there is a submit button that fires a code routine that takes some time to run.

Unfortunately, with a good number of users still using old internet browsers and some running no-script addons. I cannot use javascript.

Is there a way to disable a button after clicking a button in asp.net?

4
  • Not sure why this was downvoted... I think OP asked a sensible question Commented Jan 10, 2013 at 15:44
  • Alternative solution for long running process is release the UI and pass the task to another thread. For example, once user clicks on button, post back to server and schedule the task (let background thread performs that task). Then return to user with a message saying your task has been scheduled. Commented Jan 10, 2013 at 15:53
  • @Win That round trip would take a second or two, possibly longer with a slow connection. Double clicks happen very quickly (at least potentially). Commented Jan 10, 2013 at 16:05
  • I know it's a cheeky answer, but you could use VBScript (which is technically not JavaScript). Commented Jan 10, 2013 at 16:08

5 Answers 5

2

Since you want to disable the button after the user has clicked (and while your page is still loading) it has to be done on client side. JavaScript is the only client-side language you can use for this.

So make sure that if the user has Javascript disabled (highly unlikely these days), that your end-page can deal with "double submitted" data.

Sign up to request clarification or add additional context in comments.

Comments

1

Short story, no.

In your situation, you would need to make some server side code to detect a double post, and then discard the duplicate request.

Comments

0

You can start timer on server after each button click and put it in session. On next click you can check timer and apply or decline next user click.

Comments

0

So it will be impossible to disable the button without some kinda of client side scripting. If you assume that it will be disabled, no matter what kinda of client side script it is, then that's an impossible task.

What you can do is ensure that the operation they're trying to perform won't ever be run more than once per page load.

  1. When loading the page create a hidden field; populate that field with a GUID.
  2. At the start of the server side click handler enter a Lock block.
  3. Check for the existence of a session key based on that GUID. (Give it a prefix so it won't collide with any other GUID based session key.)
  4. If the key existed, exit the lock block and do nothing, or display an error message of some sort.
  5. If they key didn't exist, then add a new value to that session key, exit the lock block, and do your operation. Give the session key an appropriate expiration time; it shouldn't need to be more than a handful of minutes. You could even remove the relevant session key at the end of the operation, if it makes sense for it to be repeated at that point.

Comments

-3

in button click event just write the code

{

//Some Code

button1.Enabled = false;

}

2 Comments

This doesn't address the issue of the user clicking the button a 2nd time before the page has been refreshed (think about how long it takes to upload a large file)
Did you see the part of the question that said "without Javascript"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.