Disable Linkbutton Before Postback?

A

Al Cohen

I'm using a LinkButton to call some code, then do a redirect. The code
does some queries, sends some emails, and takes a few moments before the
redirect is performed.

I'd like to disable my LinkButton during this period to prevent multiple
submissions. (Obviously) the disabling should be done at the client
side to prevent any delay. I've tried adding some javascript to
LinkButton.Attributes:

LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'"
+ this.GetPostBackEventReference(this.LinkButton1));

but this doesn't disable the LinkButton. I also tried:

LinkButton1.Attributes.Add("onclick", "this.href='javascript:void(0)'");

which disables the link, but never does the postback.

This seems like a very important thing to be able to do, and thus it
should be reasonably easy - what am I missing?

Alternatively, perhaps there's something clever that I can do on the
server side to "short circuit" subsequent postbacks?

Thanks,

Al Cohen
 
R

Rick Strahl [MVP]

Hi Al,

I've had that same issue. Usually you have to attach the script code to the
form's OnSubmit().

Actually what I found is that if you disable the button that you're binding
events to the button's event doesn't fire because the button doesn't show up
in the post variable list. Hiding the button actually works better.

I usually do this in the HTML but you should be able to do the same with
attributes:

<form id="frmOrderForm"
onsubmit="this.btnSubmit.style.display='none';document.getElementById('WaitN
ote').style.display='inline';return true;" ... >

This code hides the button and shows an area that has a message.

Works real well, except that I have an animated Gif in there and it doesn't
animate - some bug in IE related to a hidden image not animating, it works
with Mozilla...

+++ Rick ---

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/blog/
 
A

A

Hi,
a solution that allways works, even if the user presses F5, or disables
javascript

I normaly insert a database value (ID, Identity) in a hidden form, when the
"updating" or other stuff takes place, it first checks if the value (ID) is
in the database, if it is there updating takes place and the ID is deleted,
if it is NOT there i tell the user that their data is allready saved,
problerly because they hit the submit button twice...

Regards,

Agge
 
R

Rick Strahl [MVP]

Yes that is good practice. I think a more general approach should be taken
to this sort of thing, where your code should set something right away that
in teh DB that lets it know that the process has already started.

But I still think from a UI perspective it's smart to use something on the
client side to disable the button.

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/
http://www.west-wind.com/blog/
----------------------------------
Making waves on the Web


A said:
Hi,
a solution that allways works, even if the user presses F5, or disables
javascript

I normaly insert a database value (ID, Identity) in a hidden form, when the
"updating" or other stuff takes place, it first checks if the value (ID) is
in the database, if it is there updating takes place and the ID is deleted,
if it is NOT there i tell the user that their data is allready saved,
problerly because they hit the submit button twice...

Regards,

Agge

Rick Strahl said:
Hi Al,

I've had that same issue. Usually you have to attach the script code to the
form's OnSubmit().

Actually what I found is that if you disable the button that you're binding
events to the button's event doesn't fire because the button doesn't
show
up
in the post variable list. Hiding the button actually works better.

I usually do this in the HTML but you should be able to do the same with
attributes:

<form id="frmOrderForm"
onsubmit="this.btnSubmit.style.display='none';document.getElementById('WaitN
 
M

Mr.Joe

How can I stop the linkbutton at a step, and then makes it go on to he
next step????
 
G

Guest

I dont really understand what you are trying to ask, but as far as I can
guess, you want to disable a link button without postback?
Here is something I did long time ago, I put the linkbutton in a div tag and
used javascript to show and hide it without postback..
Does this suite ur situation?
Hth...
R. Thomas
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top