ValidationSummary displayed multiple times in UpdatePanel

by Arnold Matusz 14 10 2008

Restricting the user from leaving certain fields blank is often mandatory, because we don't want to have empty fields in our database, or we may want the user to specify exactly how many products he wishes to order. Asp.net comes in really good here with the Validation Controls. For my example the RequiredFieldValidator is perfectly suited because it displays a little error message for the control it validates.

All is fine until you have 40-50 fields that have to be filled out. In this case it's of good practice to use the ValidatioSummary control which summarises all the error messages from the ValidationGroup and shows them either in text on the page or as a Javascript alert(). 

All is fine again until you use the ValidationSummary inside an UpdatePanel, where something rather interesting happens. The alert box is displayed multiple times. When I got this behaviour it was even more interesting that the number of times the alert box is displayed was not constant. Many readers will immediately tell me that Microsoft admits that Validation Controls don't work well with the Asp.net AJAX UpdatePanel. Furthermore other readers will tell me that there is a certain validators.dll out there, and by defining some TagMappings in the web.config file all UpdatePanel Validation controversies will be solved. And yes sir, this is all true, but this still won't solve the ValidationSummary multiple alert() situation in the UpdatePanel.

Later I've noticed that there is a correlation between the number of times the alert is displayed and the number of asynchronous postbacks in that UpdatePanel. Yes, the ValidationSummary alert() is displayed exactly the number of asychronous postbacks times plus one. (0 postbacks --> 1 alert, 2 postbacks ---> 3 alerts)

To avoid this behaviour you only have to place the ValidationSummary outside the UpdatePanel, this will prevent it from reregistering itself for validation on each asynchronous postback.

DZone it Digg it Submit to StumbleUpon Submit to Technorati Submit to reddit.com Submit to del.icio.us Submit to NewsVine Submit to Furl Submit to BlinkList

Tags: , ,

AJAX | ASP.NET | Programming

Comments

10/15/2008 1:45:29 AM #

trackback

Trackback from DotNetKicks.com

ValidationSummary displayed multiple times in UpdatePanel

DotNetKicks.com | Reply

12/3/2008 12:25:56 AM #

kapil gupta

i m trying this. put validation Summary Control outside the Update Panel but its does'nt works.

kapil gupta
9871461528

kapil gupta India | Reply

12/3/2008 12:29:33 AM #

arnold

Hello Kapil

Would you please write me an email with your code? or you could post it in a comment so we can see what may be wrong?

I hope I can help you!

arnold United States | Reply

12/11/2008 6:47:47 PM #

Arnold Matusz

Hello Kapil
I received your code in a comment, but kindly accept the fact that it simply was to long for me to approve. I've contacted you through email (maybe my message landed in your spam folder), but in any way, please send me the file through email (you can either send it through my contact form, or use the email I contacted you from). Don't forget to send both .aspx and .cs files.

Kind regards

Arnold Matusz United States | Reply

3/1/2009 6:33:40 PM #

Ashbind P

I am developing a ajax enabled website.Here what i need is to use validation any controls in in ModularPopupExtender...IS this possible

Please let me know

Ashbind P India | Reply

3/1/2009 7:23:08 PM #

Arnold Matusz

I am developing a ajax enabled website.Here what i need is to use validation any controls in in ModularPopupExtender...IS this possible

Of course this is possible, you'll be able to use your validation controls inside the ModalPopupExtender in the same way you do on normal pages.

There is one more recommendation I'ld do, you should use the ValidationGroup property of your Valitators and the Submit button which should be set to the same value.

ValidationGroup = "MyValidationGroup" on all Validators and the Submit button which saves the information.

Arnold Matusz Romania | Reply

4/8/2009 8:52:51 PM #

olka

thx, it helps me Smile

olka Ukraine | Reply

5/11/2009 2:45:28 PM #

Dennis Wong

Hi Arnold!

Your post helped me alot!!
I've gone to several sites to find the answers, but the posts there kept skirting the issue, and said that it'd not work in multiple views with multiple validationgroups.
Which were not making sense.
I googled deeper, and found your blog.

This is excellent!
Thanks very much!

Dennis Wong Singapore | Reply

12/29/2009 3:48:00 PM #

Vaishali

This post helped me resolve my issue of multiple javascript alerts. Thanks.

Vaishali India | Reply

Leave a message

(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



About Arnold Matusz

Arnold Matusz

My name is Arnold Matusz. I'm a web developer specialized in .NET technologies with a passion for photography and cars.

View Arnold Matusz's profile on LinkedIn

Who's amung us