asp:Button client-side events

  • Thread starter Thread starter Jeff
  • Start date Start date
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'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
 
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();
 
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.
 
Back
Top