473,406 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to stop users from clicking buttons more than once?

I have a C# asp.net page that when you click a button, it writes a record
(based on entered values) to the database. I've found that if you click the
button multiple times quickly, multiple records are written. What is the
best way to deal with this? The page takes a few seconds to process after
the button is clicked so it doesn't reach the point to be reloaded with the
button disabled. I tried disabling it with Javascript, but then the server
side events didn't fire. I tried setting a session variable as soon as the
button was clicked and only running the code if the variable was not set,
but that didn't work either. What is the best way to do this?
Thanks,
Jul 21 '05 #1
8 1370
A possible way to do this would be to have some client JavaScript that
onSubmit :
- hides the form
- shows a DIV (that basically contains a "Processing. Please wait..."
message)

Patrice

"Brent" <b@b.com> a écrit dans le message de
news:10*************@corp.supernews.com...
I have a C# asp.net page that when you click a button, it writes a record
(based on entered values) to the database. I've found that if you click the button multiple times quickly, multiple records are written. What is the
best way to deal with this? The page takes a few seconds to process after
the button is clicked so it doesn't reach the point to be reloaded with the button disabled. I tried disabling it with Javascript, but then the server
side events didn't fire. I tried setting a session variable as soon as the
button was clicked and only running the code if the variable was not set,
but that didn't work either. What is the best way to do this?
Thanks,

Jul 21 '05 #2
Hi Brent,

"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
I have a C# asp.net page that when you click a button, it writes a record
(based on entered values) to the database. I've found that if you click the button multiple times quickly, multiple records are written. What is the
best way to deal with this? The page takes a few seconds to process after
the button is clicked so it doesn't reach the point to be reloaded with the button disabled. I tried disabling it with Javascript, but then the server
side events didn't fire. I tried setting a session variable as soon as the
button was clicked and only running the code if the variable was not set,
but that didn't work either. What is the best way to do this?
Thanks,


One way to do this would be to generate a unique ID (i.e. Guid.NewGuid)
and put it in the view state of the page. Create a table to keep track of
the unique IDs. When the page is posted, get the unique ID from the view
state and verify that it isn't in the table. If it isn't in the table, add
it to the table and process normally. If it is already in the table, don't
do any processing.

Regards,
Daniel
Jul 21 '05 #3
One technique I used was to write some client-side JavaScript that made the
button invisible as soon as it was clicked. You can't click what you can't
see...
"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
I have a C# asp.net page that when you click a button, it writes a record
(based on entered values) to the database. I've found that if you click
the
button multiple times quickly, multiple records are written. What is the
best way to deal with this? The page takes a few seconds to process after
the button is clicked so it doesn't reach the point to be reloaded with
the
button disabled. I tried disabling it with Javascript, but then the server
side events didn't fire. I tried setting a session variable as soon as the
button was clicked and only running the code if the variable was not set,
but that didn't work either. What is the best way to do this?
Thanks,


Jul 21 '05 #4
A ruler across the knuckles?

Dale

"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
I have a C# asp.net page that when you click a button, it writes a record
(based on entered values) to the database. I've found that if you click the button multiple times quickly, multiple records are written. What is the
best way to deal with this? The page takes a few seconds to process after
the button is clicked so it doesn't reach the point to be reloaded with the button disabled. I tried disabling it with Javascript, but then the server
side events didn't fire. I tried setting a session variable as soon as the
button was clicked and only running the code if the variable was not set,
but that didn't work either. What is the best way to do this?
Thanks,

Jul 21 '05 #5
Just to update, how I did this, was to use a session variable.
Session["adding_started"]=true until processing is done. Then on button
click, check if it is true, if so, don't do anything. Easiest way I think.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
One technique I used was to write some client-side JavaScript that made the button invisible as soon as it was clicked. You can't click what you can't
see...
"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
I have a C# asp.net page that when you click a button, it writes a record
(based on entered values) to the database. I've found that if you click
the
button multiple times quickly, multiple records are written. What is the
best way to deal with this? The page takes a few seconds to process after the button is clicked so it doesn't reach the point to be reloaded with
the
button disabled. I tried disabling it with Javascript, but then the server side events didn't fire. I tried setting a session variable as soon as the button was clicked and only running the code if the variable was not set, but that didn't work either. What is the best way to do this?
Thanks,

Jul 21 '05 #6
But there's still a risk that the second request could be buffered long
enough for the server to complete its task, in which case you will still get
2 or more executions.

You said that disabling or making the button invisible using client-side
scripting didn't work... why not?

--
John Wood
EMail: first name, dot, last name, at priorganize.com

"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
Just to update, how I did this, was to use a session variable.
Session["adding_started"]=true until processing is done. Then on button
click, check if it is true, if so, don't do anything. Easiest way I think.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
One technique I used was to write some client-side JavaScript that made

the
button invisible as soon as it was clicked. You can't click what you can't
see...
"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
I have a C# asp.net page that when you click a button, it writes a record (based on entered values) to the database. I've found that if you click the
button multiple times quickly, multiple records are written. What is the best way to deal with this? The page takes a few seconds to process

after the button is clicked so it doesn't reach the point to be reloaded with the
button disabled. I tried disabling it with Javascript, but then the server side events didn't fire. I tried setting a session variable as soon as the button was clicked and only running the code if the variable was not set, but that didn't work either. What is the best way to do this?
Thanks,


Jul 21 '05 #7
Well, seems to be good enough anyway... I tapped the button as fast as I
could, and it didn't write 2 records, so no worries. I don't think I was
doing the client side correctly. It would disable it and then not process
anything. Oh well though, this seems to work "good enough". We'll see I
guess...

"John Wood" <j@ro.com> wrote in message
news:ef**************@tk2msftngp13.phx.gbl...
But there's still a risk that the second request could be buffered long
enough for the server to complete its task, in which case you will still get 2 or more executions.

You said that disabling or making the button invisible using client-side
scripting didn't work... why not?

--
John Wood
EMail: first name, dot, last name, at priorganize.com

"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
Just to update, how I did this, was to use a session variable.
Session["adding_started"]=true until processing is done. Then on button
click, check if it is true, if so, don't do anything. Easiest way I think.

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
One technique I used was to write some client-side JavaScript that
made the
button invisible as soon as it was clicked. You can't click what you can't see...
"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
>I have a C# asp.net page that when you click a button, it writes a record > (based on entered values) to the database. I've found that if you click > the
> button multiple times quickly, multiple records are written. What is the > best way to deal with this? The page takes a few seconds to process

after
> the button is clicked so it doesn't reach the point to be reloaded with > the
> button disabled. I tried disabling it with Javascript, but then the

server
> side events didn't fire. I tried setting a session variable as soon

as the
> button was clicked and only running the code if the variable was not

set,
> but that didn't work either. What is the best way to do this?
> Thanks,
>
>



Jul 21 '05 #8
I was really thinking about a low-bandwidth line, like dial-up perhaps. But
if you're satisfied...

--
John Wood
EMail: first name, dot, last name, at priorganize.com

"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
Well, seems to be good enough anyway... I tapped the button as fast as I
could, and it didn't write 2 records, so no worries. I don't think I was
doing the client side correctly. It would disable it and then not process
anything. Oh well though, this seems to work "good enough". We'll see I
guess...

"John Wood" <j@ro.com> wrote in message
news:ef**************@tk2msftngp13.phx.gbl...
But there's still a risk that the second request could be buffered long
enough for the server to complete its task, in which case you will still get
2 or more executions.

You said that disabling or making the button invisible using client-side
scripting didn't work... why not?

--
John Wood
EMail: first name, dot, last name, at priorganize.com

"Brent" <b@b.com> wrote in message
news:10*************@corp.supernews.com...
Just to update, how I did this, was to use a session variable.
Session["adding_started"]=true until processing is done. Then on button click, check if it is true, if so, don't do anything. Easiest way I think.
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
> One technique I used was to write some client-side JavaScript that made the
> button invisible as soon as it was clicked. You can't click what you

can't
> see...
>
>
> "Brent" <b@b.com> wrote in message
> news:10*************@corp.supernews.com...
> >I have a C# asp.net page that when you click a button, it writes a

record
> > (based on entered values) to the database. I've found that if you

click
> > the
> > button multiple times quickly, multiple records are written. What is
the
> > best way to deal with this? The page takes a few seconds to
process after
> > the button is clicked so it doesn't reach the point to be reloaded

with
> > the
> > button disabled. I tried disabling it with Javascript, but then the server
> > side events didn't fire. I tried setting a session variable as soon as the
> > button was clicked and only running the code if the variable was

not set,
> > but that didn't work either. What is the best way to do this?
> > Thanks,
> >
> >
>



Jul 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: brendan | last post by:
Sorry this isnt a cross post .. i just didnt get any help from alt.php. I have a website which utilises post forms for navigation in some areas. Problem is, when *some* users hit the BACK button...
8
by: Eric Osman | last post by:
My javascript program has reason to want to stop. For example, function A has 5 lines, the second of which calls function B, which has 5 lines, the first of which calls function C. But...
16
by: deko | last post by:
I have a sub routine that searches the Outlook PST for a message sent to/from a particular email address. Obviously, this can take a long time when the PST contains thousands of messages. I'd...
0
by: Adrian Stovold | last post by:
I've written an ASP.NET application in VB.NET. It works fine on all Windows platforms and browsers, but there's a problem on the Mac version of IE (v5.1.5) running on Mac OS 9.2. I can reproduce...
10
by: Jim Bayers | last post by:
We need to stop students from clicking on the form button more than once. We have a form that students fill out with their credit card information. They click, the form sends the data in xml to...
6
by: pmud | last post by:
Hi, I have created a very simple ASP.NET application which has a couple of ImageButtons which go to different SQL reports on clicking them. I have used Response.Redirect to send the user to the ...
8
by: carriolan | last post by:
Hi I have an MS Access based application almost ready for distribution to the public and I find that even though I have compiled it into an MDE file, tables and queries can still be be imported if...
10
by: Mark | last post by:
All, I have a procedure which checks the users Outlook Inbox for the existance of an email from a specific address. If one is found, a question is asked to the user asking if they wish to allow...
1
by: stoprsi | last post by:
RSI Warrior 4.0 is an award-winning ergonomics software package helping thousands of computer users prevent and recover from computer-related Repetitive Strain Injuries such as carpal tunnel,...
5
by: Tony | last post by:
I am continuing to develop an Access 2007 application which was originally converted from Access 2003. In Access 2003 I was able to disable the Access Close button in the top righthand corner of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.