Thursday 15 March 2007

__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.

44 comments:

  1. Thanks, you really saved my bacon with that one!

    ReplyDelete
  2. 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"

    ReplyDelete
  3. thank God for this!! i've been googling for hours on how to solve this. CausesValidation=false did it for me. life saver!!

    ReplyDelete
  4. You'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...

    ReplyDelete
  5. I 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.

    ReplyDelete
  6. Ok. 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.

    But 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.

    ReplyDelete
  7. You're awesome!

    ReplyDelete
  8. Thank 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.

    ReplyDelete
  9. This 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!!.
    Many thanks

    ReplyDelete
  10. Thanks for your post!
    I 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" "

    ReplyDelete
  11. I had the LinkButton only worked once problem. Added CausesValidation="false", now works like a charm. Thanks Rowan

    ReplyDelete
  12. Thanks dude, as everybody else has said, this saved me hours of useless research time that I would have spent.

    ReplyDelete
  13. Thankyou so much .. I was facing the same problem ..your post saved me a lot of time ..

    ReplyDelete
  14. Thanks a million! I had disabled (enabled=false) my validators in a user control. I would have never found this.

    ReplyDelete
  15. Great Thanks to you.

    ReplyDelete
  16. Great Thanks to you.

    ReplyDelete
  17. you 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

    ReplyDelete
  18. Thank's this was what I searched for

    ReplyDelete
  19. Perfect, after two days of googling this was a breath of fresh air. You saved me!!!

    ReplyDelete
  20. Great work! This appears to have fixed a problem with controls assigned as triggers to an update panel which randomly stop working (__postback function).

    In 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.

    ReplyDelete
  21. Thanks soooo much.

    ReplyDelete
  22. thanks, it's really helped me. great article.

    ReplyDelete
  23. Thanks! Worked like a Charm.....

    ReplyDelete
  24. Hi ya, Thanks so much really.

    ReplyDelete
  25. Thank you - after two hours, this fixed my issue.

    ReplyDelete
  26. Thanks.
    You save my day!!
    Explained in simple terms.

    ReplyDelete
  27. Still a life saver 5 years on... thank you.

    ReplyDelete
  28. i 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???

    ReplyDelete
  29. Dear 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

    ReplyDelete
  30. OOOPSSS 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 :)

    ReplyDelete
  31. Why are you doing software development if you are not a software person?

    There 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.

    ReplyDelete
  32. Thank you dude.
    Now, my buttons are CauseValidation = false.

    ;)

    ReplyDelete
  33. Awesome Help. Knowledge always worth to share! Thank you very much!

    ReplyDelete
  34. Thanks!! This issue was killing me!!

    ReplyDelete
  35. At last!! Adding CausesValidation="false" to my link buttons solved my problem too.
    Cheers.

    ReplyDelete
  36. Man you saved me few hours of work, Thanks!!

    ReplyDelete
  37. Thanks
    At last find Solution on Your blog after 2 hours searching
    God Bless You


    Imran Ullah Khan Pakistan

    ReplyDelete
  38. Thanks for sharing it. I wasted almost two entire days looking for a solution for this.

    ReplyDelete
  39. Your post is still saving asses almost a decade after it was posted.

    ReplyDelete