user1048083
user1048083

Reputation: 93

Disable 'submit' button without javascript

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?

Upvotes: 1

Views: 602

Answers (5)

Servy
Servy

Reputation: 203848

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.

Upvotes: 0

Pandian
Pandian

Reputation: 9136

in button click event just write the code

{

//Some Code

button1.Enabled = false;

}

Upvotes: -3

Frank59
Frank59

Reputation: 3261

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.

Upvotes: 0

Tejs
Tejs

Reputation: 41266

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.

Upvotes: 1

Jules
Jules

Reputation: 7233

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.

Upvotes: 2

Related Questions