Disable Button after Click whilst maintaining CausesValidation and an OnClick-Method?

Just override the Onload event of your page or master page with.

Just override the Onload event of your page or master page with protected override void OnLoad(EventArgs e) { base. OnLoad(e); // prevents form from being submitted multiple times in MOST cases // programatic client-side calls to __doPostBack() can bypass this Page.ClientScript. RegisterOnSubmitStatement(GetType(), "ServerForm", "if (this.

Submitted) return false; this. Submitted = true; return true;"); }.

Works nicely, also by far the leanest idea, I don't need to disable the button and Validation/Onclick work regardless, thanks! – Dennis Röttger Dec 15 at 15:20.

Try the following in Page_Load VB Dim postBackOptions As PostBackOptions = New PostBackOptions(btnSubmit) btnSubmit. OnClientClick = "this. Disabled=true;" btnSubmit.

OnClientClick += ClientScript. GetPostBackEventReference(postBackOptionClaim) C# PostBackOptions postBackOptions = new PostBackOptions(btnSubmit); btnSubmit. OnClientClick = "this.

Disabled=true;"; btnSubmit. OnClientClick += ClientScript. GetPostBackEventReference(postBackOptionClaim).

Nevermind, that works now - Next problem: Page is not valid, Button click is fired, Button validates page, Validators throw their ErrorTexts, all is well - except that the button stays disabled because no PostBack was raised. Ideas? – Dennis Röttger Dec 15 at 14:25.

EDIT if(Page_ClientValidate()) {this. Visibility='hidden';} If you need to have server side validation before you know whether to hide/disable the button or not you'll probably want to forgo the disabling of the button and just make sure your server-side code doesn't execute more than necessary if a user hammers on the button. You could put a hidden field and generate a GUID for it in the page_load if(!IsPostBack) then on your btnSubmit_click do something like if(SessionPage.ToString() + "_spam"!

= null && SessionPage.ToString() + "_spam" == hdnGuid. Value) { return } else { SessionPage.ToString() + "_spam" = hdnGuid. Value; //do stuff }.

Yes, clearly that would work just as well as disabling, but it's still something that I need to activate onclick. – Dennis Röttger Dec 15 at 14:08 @Dennis Röttger - You want to hide the button only if everything is valid so use the Page_ClientValidate() to check before hand if everything is correct. – LastCoder Dec 15 at 14:33.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions