__doPostBack works, WebForm_DoPostBackWithOptions doesn't! Heeelp!
I've seen many a forum and blog entries that look like the title of this entry. I was frantically trying to find the solution for this a few hours ago and found a lot of questions of the same type, most of them abruptly ending into nothing. No solution, only the questions. What was I to do? Debug!
The problem was that buttons with __doPostBack seemed to work and those with WebForm_DoPostBackWithOptions did not. I pressed them and nothing happened.
Debugging the hell out of the two javascript functions (both used by NET 2.0, on who knows what conditions) I realized that the problem was not in the javascript functions! The problem was a false one.
The real problem is in the validators. If you have a validator on a field and the field has some wrong values in it and both field and validators are hidden, the submit will not work and you will not see what the problem is. Let me make this simple: if you have problems with submit buttons that seem not to work, check your validators!
Now, why the field was hidden and its values filled and the validator enabled is a problem, but that I can fix easily. The "Oh, I am so stupid" phenomenon probably stopped a lot of people posting the solution after they found it.
The problem was that buttons with __doPostBack seemed to work and those with WebForm_DoPostBackWithOptions did not. I pressed them and nothing happened.
Debugging the hell out of the two javascript functions (both used by NET 2.0, on who knows what conditions) I realized that the problem was not in the javascript functions! The problem was a false one.
The real problem is in the validators. If you have a validator on a field and the field has some wrong values in it and both field and validators are hidden, the submit will not work and you will not see what the problem is. Let me make this simple: if you have problems with submit buttons that seem not to work, check your validators!
Now, why the field was hidden and its values filled and the validator enabled is a problem, but that I can fix easily. The "Oh, I am so stupid" phenomenon probably stopped a lot of people posting the solution after they found it.
Thanks, you really saved my bacon with that one!
ReplyDeleteI had the same problem using LinkButtons. If you clicked on the link twice or more in IE 6 then the links would stop working.
ReplyDeleteI was able to fix it by adding this to the LinkButton tag:
CausesValidation="false"
thank God for this!! i've been googling for hours on how to solve this. CausesValidation=false did it for me. life saver!!
ReplyDeleteYou're a life saver, I've been racking my brain (and the net) for hours trying to figure it out... Damn Microsoft they couldn't have made this one easy...
ReplyDeleteI had the same problem with the Finish button in the Wizard. I change to using Panels instead and still had the same problem. CausesValidation=false worked for me. What's up with that? Thanks again.
ReplyDeleteOk. The solution is to find out which validator causes the problem. You should know that if you made the page and all, since you are the one putting validators there.
ReplyDeleteBut let's assume that you don't know what is going on. The best solution is to see what the Page_Validators array contains (in Javascript) and what is their controltovalidate value.
Something like javascript:alert(Page_Validators[0].controltovalidate); in your browser address bar should do the trick to show you the control that the first validator (if any) is trying to validate. The property might be controlToValidate, I am not sure about the casing and I am too tired to test it out.
You're awesome!
ReplyDeleteThank you!! I had neglected to add a validation summary to my page so my control, which was bubbling up errors to the page had nowhere to display them. All the errors displayed inline, but clicking Submit did nothing to highlight this fact.
ReplyDeleteThis post has just save me from pulling my hair. I had CommandField in a GridView but when you edit a press update nothing happens and have wasted a lot of hours trying to figure it out. After setting CausesValidation="false" it is working ok!!.
ReplyDeleteMany thanks
Thanks for your post!
ReplyDeleteI had spent a lot of time on that problem...
Thanks to rowan, too.. I had the same problem..
quote: " rowan said...
I had the same problem using LinkButtons. If you clicked on the link twice or more in IE 6 then the links would stop working.
I was able to fix it by adding this to the LinkButton tag:
CausesValidation="false" "
I had the LinkButton only worked once problem. Added CausesValidation="false", now works like a charm. Thanks Rowan
ReplyDeleteThanks dude, as everybody else has said, this saved me hours of useless research time that I would have spent.
ReplyDeleteThankyou so much .. I was facing the same problem ..your post saved me a lot of time ..
ReplyDeleteThanks a million! I had disabled (enabled=false) my validators in a user control. I would have never found this.
ReplyDeleteGreat Thanks to you.
ReplyDeleteGreat Thanks to you.
ReplyDeleteYou are welcome.
ReplyDeleteyou are doing a great things to the world of developers.thanks a lot for ur articles and solutions to bugs (especially for ajax related javascript errors hats off to you and ur talent.) very happy in greeting you. wish you all success in your endeavours.Great thanks to you
ReplyDeleteThank's this was what I searched for
ReplyDeletePerfect, after two days of googling this was a breath of fresh air. You saved me!!!
ReplyDeleteGreat work! This appears to have fixed a problem with controls assigned as triggers to an update panel which randomly stop working (__postback function).
ReplyDeleteIn my case, I would often leave the page and do some work, come back to the site only to find the controls no longer functioning.
I have now added causesvalidation="false" to all of my controls hooked up as triggers to an updatepanel.
Thanks soooo much.
ReplyDeletethanks, it's really helped me. great article.
ReplyDeleteThanks! Worked like a Charm.....
ReplyDeleteHi ya, Thanks so much really.
ReplyDeleteThank you - after two hours, this fixed my issue.
ReplyDeleteThanks.
ReplyDeleteYou save my day!!
Explained in simple terms.
Still a life saver 5 years on... thank you.
ReplyDeletei am having the same problem and still dont get whatever u ppl are saying :( what is a validatr?? whr to find it?? where to put this causes validation thing???
ReplyDeleteDear Anonymous, I thought long and hard before answering, oscillating between swear words, insults and blaming you and your kind for all software ills to the desire to actually help you, even if you seem unable to even ask for it in a decent way. But I think the best possible answer is a classic: http://lmgtfy.com/?q=ASP.Net+Validator
ReplyDeleteOOOPSSS sorrryyyy!! if i was rude but was in hurry and yes i really dont get it because m not a software person as u said a software ill :P. I have to fill up a webform but the SAVE button is not active and my work is getting late day by day and i literally dont know how to resolve this problem. If u cud help me through this i'll be reallyyy thankful to you :)
ReplyDeleteWhy are you doing software development if you are not a software person?
ReplyDeleteThere isn't much I can say outside of what is in the post. You should look for ASP.Net controls that end in "Validator" somewhere in the aspx, ascx or maybe instantiated in the code. A control that contains those validators or even an html container that are hidden via styling is what is wrong with your page. A validator control is always associated with an input control, like a textbox or text input or checkbox, radio button, select, etc.
To check this from the browser, rather than from within the code, use a DOM inspector (all major browsers have one included nowadays) and look for hidden container elements. Make them show (by removing the display:none style attribute) and maybe you will see the validator that is throwing the error and stopping you from doing a postback.
Thank you very much!!
ReplyDeleteThank you dude.
ReplyDeleteNow, my buttons are CauseValidation = false.
;)
Ty alot!
ReplyDeleteAwesome Help. Knowledge always worth to share! Thank you very much!
ReplyDeleteThanks a lotz
ReplyDeleteThanks!! This issue was killing me!!
ReplyDeleteAt last!! Adding CausesValidation="false" to my link buttons solved my problem too.
ReplyDeleteCheers.
thanks a lot!
ReplyDeleteMan you saved me few hours of work, Thanks!!
ReplyDeleteThanks
ReplyDeleteAt last find Solution on Your blog after 2 hours searching
God Bless You
Imran Ullah Khan Pakistan
Thanks for sharing it. I wasted almost two entire days looking for a solution for this.
ReplyDeleteYour post is still saving asses almost a decade after it was posted.
ReplyDelete