Click here to Skip to main content
Licence CPOL
First Posted 15 Nov 2007
Views 32,285
Bookmarked 22 times

Using Validation Controls on an UpdatePanel having an AJAX PopupExtender

By | 15 Nov 2007 | Article
UpdatePanel is not compatible with the ASP.NET validation controls in the current release. Here is a solution to solve the problem.

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. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralNeeed source code for the same Pinmemberrama charan16:56 11 Dec '07  
GeneralPatch Pinmembermiies22:20 15 Nov '07  
GeneralRe: Patch PinmemberGyan Jadal8:51 16 Nov '07  
GeneralRe: Patch PinmemberJawad Munir2:15 4 Dec '07  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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