asp:Button client-side events

J

Jeff

I need to intercept the Click event of a asp:Button on the client side
so that i can disable it after they've clicked it... HOW can i do
this??

I was thinking of making the button an HTML button and handling the
__doPostback myself... BUT, my page does have some asp:Validator
controls on it, so I don't know how to mimic the logic for calling the
validation functions properly.

Is there ANY way i can make the asp:Button call some of MY Javascript
before it calls the .Net validation/postback stuff??

jeffpriz
 
I

Ivan

I'm not sure i've understood your problem.... anyway, you
can try the set causeValidation to false and then when the
buttons is clicked you disable it.
Ivan
 
T

Teemu Keiski

For client-side validation, if you check the code when there are buttons, is
Page_ClientValidate the relevant function. The call for it is exactly of
form:

if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate();
 
D

David

I need to intercept the Click event of a asp:Button on the client side
so that i can disable it after they've clicked it... HOW can i do
this??

I was thinking of making the button an HTML button and handling the
__doPostback myself... BUT, my page does have some asp:Validator
controls on it, so I don't know how to mimic the logic for calling the
validation functions properly.

Is there ANY way i can make the asp:Button call some of MY Javascript
before it calls the .Net validation/postback stuff??

If you set the onclick attribute of the button to your own code in
Page_Load (e.g. Button1.Attributes["onclick"] = "this.disabled =
true;";), then ASP.NET will add the validation stuff onto the end of
your own code. But if you disable the button before validation there's
the danger that client-side validation will fail leaving your user with
a disabled button, plus there's the problem that a disabled button won't
send it's name/value info in the submitted form, which means that the
server side event handler will be missed.

If you're just trying to stop the user from pressing the submit button
multiple times, you might be interested in the OneClick control from
http://www.metabuilders.com (warning, I haven't used this control at
all, although other controls from the site have worked great for me).
There's a good discussion of the problem there as well.

PS. No, I'm not affiliated with metabuilders in any way.
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top