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

Using Validation Controls on an UpdatePanel having an AJAX PopupExtender

, 15 Nov 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Gyan Jadal
Architect
United States United States
Software Architect

Comments and Discussions

 
GeneralNeeed source code for the same Pinmemberrama charan11-Dec-07 16:56 

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.

| Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 15 Nov 2007
Article Copyright 2007 by Gyan Jadal
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid