Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prevent the user from clicking twice

Status
Not open for further replies.

netangel

Programmer
Feb 7, 2002
124
PT
I need to prevent the user from clicking twice or more on an insert button, when the insert command takes too long. I've thought about sending the data to insert to a dumb page with no buttons that only says 'Please wait while saving your data'. My problem is that the data to save includes a file to upload to the database, and I can't send it to the dumb page, nor save it to the server disk.

This leaves me with the possibility to disable the insert button after the first click. So I put the following code on the 'onclick' event:
MyInsertButton.Attributes.Add("onclick", "MyInsertButton.disabled=true;Form1.submit();")

Now the insert button doesn't submit.

How can I get arround this problem? NetAngel
 
So far I've figuered out something else.
It does submits. It runs thru the Load event, but it just misses the MyInsertButton_Click event. It doesn't handle the event.
If I remove the onclick Attribute it handles the MyInsertButton_Click.

How can I, in client script, force the submit to handle the MyInsertButton_Click event? NetAngel
 
That site only tells you how to disable the button. I already do that. My problem is that when I disable the button on the click event, the button doesn't submit the form, and if I forrce it by using 'Form1.submit()', it does submit, but not by the button click, so, It doesn't call my server event for that click.

Thanks anyway for your help.
NetAngel
 
then, by that same function where you call form.submit(), you might also set the value of a hidden form element, and check the value of that element in your page_load event.

This would serve the same purpose as "raising a click event", just that it's not done in the literal sense.

Just fire off the same routines when the value of that variable is set, and the net effect should be the same.

:)
paul
penny1.gif
penny1.gif
 
Thanx. It sort of work, with a few changes. I had to put the code on the click of the button instead of the form submit to avoid catching all the button clicks as an insert (I have more buttons on the form), and I had to use a textbox with a zero width instead of the hidden to be able to catch the value property back on the server.

Thank you for your help.
NetAngel
 
I just ran across this today and thought you might be able to use it.

Canceling a Button Click
The following HTML example shows a common scripting mistake related to event handling and canceling the default action.

<HTML>
<HEAD><TITLE>Canceling the Default Action</TITLE>
<SCRIPT LANGUAGE=&quot;JScript&quot;>
function askConfirm()
{ return window.confirm (&quot;Choose OK to follow hyperlink, Cancel to
not.&quot;)
}
</SCRIPT>
<BODYonload=&quot;b3.onclick=askConfirm&quot;>
<!-- Try links with different hookups - should be canceled by &quot;Cancel&quot; to confirm dialog. -->

<BR><A NAME=b1 HREF=&quot; onclick=&quot;askConfirm()&quot;>1 Without return (won't work)</A>

<BR><A NAME=b2 HREF=&quot; onclick=&quot;return askConfirm()&quot;>2 With return (works)</A>

<BR><A NAME=b3 HREF=&quot; Function pointer (works)</A>

</BODY>
</HTML>

The first a element in this example does not work properly. Without the return in the onclick JScript expression, the browser interprets the function expression, throws away the resulting value, and leaves the default action unaffected.

The other a elements correctly bind the return value to the event, hence the default action can be canceled when false is returned.
That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top