Disable a button with javascript

  • Thread starter Thread starter blarfoc
  • Start date Start date
B

blarfoc

Hi, I have to disable a button on a aspx page after the user clicks it.
I have to disable the button with javascript because the process takes
20 seconds to run the full course.

I kno I need to do this with javascript but I do not kno how.

Please tell me if you will please.
 
Hi, I have to disable a button on a aspx page after the user clicks it.
I have to disable the button with javascript because the process takes
20 seconds to run the full course.

I kno I need to do this with javascript but I do not kno how.

Please tell me if you will please.

Note that javascript is not foolproof, as a lot of useragents may not be
running javascript. So, it's best to check this on the server if you can.

However, to do it via javascript, here's a method I recently used:

I wrapped my submit button in a div, and then created another div that said
'please stand by while we update the database':

<div id="updatebutton"><asp:button /></div>
<div id="inprogress">Please stand by...</div>

Then I added this javascript to my HEAD tags:

<script lang="javascript">
function standbyShow() { // hide all the divs
document.getElementById('inprogress').style.display = 'block';
document.getElementById('updateButton').style.display = 'none'; }
</script>

and in my codebehind, I attached the above function to the onClick action of
the button:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Form1.Attributes.Add("onSubmit", "standbyShow();")
End Sub

Now, in my case, I knew the people using this would have javascript (it's
for our intranet). For a public site, I'd go a step further and populate the
'standby' text in the second div via javascript as well, so that those
without javascript won't see this odd message.

-Darrel
 
Back
Top