Disable Submit Button

J

jack-e

Hi,

Can someone please provide me with an example of how to disable the
submit button once clicked (using javascript i guess). Keep in mind I
also have to invoke a server side function which processes the form.

Thanks in advance.

Jack
 
C

Craig Deelsnyder

jack-e said:
Hi,

Can someone please provide me with an example of how to disable the
submit button once clicked (using javascript i guess). Keep in mind I
also have to invoke a server side function which processes the form.

Thanks in advance.

Jack

Use the Attributes collection to set the onclick to disabled the button
and submit normally:

button1.Attributes.Add("onclick","javascript:document.getElementById('"
+ button1.ClientID + "').disabled=true;" +
this.GetPostBackEventReference(button1));

reference:

http://www.codeproject.com/useritems/DisableSubmitButton.asp
 
E

Eliyahu Goldin

Much shorter form:

button1.Attributes.Add("onclick","this.disabled=true;return true;");

Eliyahu
 
C

Craig Deelsnyder

Eliyahu said:
Much shorter form:

button1.Attributes.Add("onclick","this.disabled=true;return true;");

Eliyahu

Use the Attributes collection to set the onclick to disabled the button
and submit normally:

button1.Attributes.Add("onclick","javascript:document.getElementById('"
+ button1.ClientID + "').disabled=true;" +
this.GetPostBackEventReference(button1));

reference:

http://www.codeproject.com/useritems/DisableSubmitButton.asp

Hmmm, that didn't seem to work for me. Could you provide sample code if
so? For completeness here....
 
P

Patrice

Try to submit the from and then to disable the button. If you disable first
the button, the button is not considered pressed (disabled control are not
posted).

Patrice

--

 
E

Eliyahu Goldin

Craig,

You can check it on any server-side button. "this" is the client-side
reference to the button itself and "return true" takes care about bubbling
the event up.

Eliyahu

 
E

Eliyahu Goldin

Could be. This I didn't check. I've just optimized the size of the code.

Eliyahu

Patrice said:
Try to submit the from and then to disable the button. If you disable first
the button, the button is not considered pressed (disabled control are not
posted).

Patrice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top