By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,919 Members | 1,587 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,919 IT Pros & Developers. It's quick & easy.

How to stop users from clicking buttons more than once?

P: n/a
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,
Nov 18 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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,

Nov 18 '05 #2

P: n/a
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
Nov 18 '05 #3

P: n/a
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,


Nov 18 '05 #4

P: n/a
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,

Nov 18 '05 #5

P: n/a
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,

Nov 18 '05 #6

P: n/a
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,


Nov 18 '05 #7

P: n/a
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,
>
>



Nov 18 '05 #8

P: n/a
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,
> >
> >
>



Nov 18 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.