Thursday, March 15, 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:

Anonymous said...

Thanks, you really saved my bacon with that one!

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"

takejiro said...

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

Anonymous said...

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

Anonymous said...

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.

Siderite said...

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.

Anonymous said...

You're awesome!

Josh Gough said...

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.

Anonymous said...

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

Massimo said...

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" "

DJ said...

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

Anonymous said...

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

neeva said...

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

Scott said...

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

RP said...

Great Thanks to you.

Anonymous said...

Great Thanks to you.

Siderite said...

You are welcome.

Padma said...

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

Anonymous said...

Thank's this was what I searched for

Anonymous said...

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

Anonymous said...

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.

Rehana said...

Thanks soooo much.

Anonymous said...

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

Anonymous said...

Thanks! Worked like a Charm.....

Anonymous said...

Hi ya, Thanks so much really.

Anonymous said...

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

Anonymous said...

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

Nick Pearce said...

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

Anonymous said...

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???

Siderite said...

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

Anonymous said...

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 :)

Siderite said...

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.

DiegoBu said...

Thank you very much!!

Bruno Monteiro said...

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

;)

Anonymous said...

Ty alot!

Tim Hong said...

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

Anonymous said...

Thanks a lotz

Anonymous said...

Thanks!! This issue was killing me!!

Al said...

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

Dominik Schenk said...

thanks a lot!

Anonymous said...

Man you saved me few hours of work, Thanks!!

Anonymous said...

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


Imran Ullah Khan Pakistan

Rajiv said...

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

Custos said...

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