Click here to Skip to main content
Click here to Skip to main content

Using Validation Controls on an UpdatePanel having an AJAX PopupExtender

By , 15 Nov 2007
 

Introduction

This article explains how to get around the problem of incompatible ASP.NET validation controls used on UpdatePanels in AJAX.

Background

UpdatePanel is not compatible with the ASP.NET validation controls in the current release. This creates a problem on popup controls created using the ModalPopupExtender control of the AJAX Toolkit.

Using the code

Let's say we have a user control which is used as an AJAX modal popup dialog.

In PopupDialog.ascx, we will have the following:

<AJAX:ModalPopupExtender ID="popup" TargetControlID="LinkButton1" 
  PopupControlID="popupControlPanel" runat="server" CancelControlID="CancelButton" /> 

The CancelControlID dictates that the popup should be hidden on clicking the CancelButton. The above works fine as long as there are no validation controls on PopupContainer. However, if a validation control is present on the popup, then that gets validated on Cancel Click, but the popup still gets hidden as expected.

If the validation was successful, then there is no problem; but if it fails, then the popup doesn't show up again even by clicking the button which opened it first time. Also, none of the AJAX postbacks will work thereafter on the page till it is refreshed.

This is because the focus is still with the control where the validation failed, which is now hidden.

Solution

To make the validators compatible with an UpdatePanel control, set the EnableClientScript property of the validators to false. This disables the client script that would ordinarily be used to perform validation in the browser. As a result, during an asynchronous postback, the validators perform validation on the server. However, because only the content of the UpdatePanel is refreshed, the validators can provide the kind of immediate feedback that is ordinarily provided by a client script.

History

  • Posted on Nov 15th 2007.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Gyan Jadal
Architect
United States United States
Member
Software Architect

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralNeeed source code for the same Pinmemberrama charan11 Dec '07 - 16:56 
hi Gyan Jadal,
Can u please upload an example with source code for the same.
thanks ..
 
Rama Charan Prasad
 
"Be happy and Keep smiling.Thats what u want be always..Smile | :) "

GeneralPatch Pinmembermiies15 Nov '07 - 22:20 
Hi,
 
Read the URLs below for more information on this problem, and a link to a semi-official MS patch, containing a set of new Validator controls to replace the default ones. With this patch installed, the validators will work as expected inside an UpdatePanel, without disabling clientscript or anything.
 
Unfortunately, since the release of this temporary patch, we haven't heard anything about it anymore. It's almost a year ago, and the patch has never been released through an official Windows update.
 
http://weblogs.asp.net/scottgu/archive/2007/01/25/links-to-asp-net-ajax-1-0-resources-and-answers-to-some-common-questions.aspx
http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx
http://blogs.msdn.com/mattgi/archive/2007/05/12/validators-update-available.aspx
 

GeneralRe: Patch PinmemberGyan Jadal16 Nov '07 - 8:51 
GeneralRe: Patch PinmemberJawad Munir4 Dec '07 - 2:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 15 Nov 2007
Article Copyright 2007 by Gyan Jadal
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid