single-click button / ajax

L

laziers

Hi,
anyone know how to write a single-cilick button? [after click button
is being disabled while the method is executing]

I use this:

<asp:button id="ButtonAdd" runat="server" text="Anuluj"
onclick="Click_ButtonAdd" />

if ( !isPostBack){
ButtonAdd.Attributes.Add("onclick",
ClientScript.GetPostBackEventReference(ButtonAdd, "") +
";this.value='Processing Credit Card Payment...';this.disabled =
true;");

}

and I have with this a big problem.

For time to time this method is executing 2 times. I dont know why.
Instend of add 1 record to database it add 2 records.
 
M

Mark Rae [MVP]

anyone know how to write a single-cilick button? [after click button
is being disabled while the method is executing]

<asp:Button ID="ButtonAdd" runat="server" Text="Anuluj"
OnClick="Click_ButtonAdd"
OnClientClick="this.value='Processing Credit Card
Payment...';this.disabled=true;" />
 
L

laziers

<asp:Button ID="ButtonAdd" runat="server" Text="Anuluj"
OnClick="Click_ButtonAdd"
OnClientClick="this.value='Processing Credit Card
Payment...';this.disabled=true;" />


ok but now, method: Click_ButtonAdd is not executing :|
 
E

Eliyahu Goldin

Aha, right, it is a different problem.

Disabled buttons don't fire postbacks.

You can do something like this:
OnClientClick="this.value='Processing Credit Card
Payment...';this.disabled=true;document.forms[0].submit()" />

It won't fire the server-side onclick event but will cause a postback. You
can communicate the action you want the server to take in a hidden input
field.


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
B

bruce barker

disabling after postback is trival.

<asp:button id="ButtonAdd"
runat="server"
text="Anuluj"
onclientclick="window.setTimeout(function(){this.disabled=true;};"
onclick="Click_ButtonAdd" />

but its a bad solution. if the postback takes too long and the user hits f5
(refresh), you will get a second postback. you should code for double
postbacks. render a transaction guid in a hidden field (or viewstate). then
store the guid with the payment posting. your code can then check if its been
processed, and display the proper response.

-- bruce (sqlwork.com)
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top