Click here to Skip to main content
15,885,026 members
Articles / Web Development / HTML

Using Validation Controls on an UpdatePanel having an AJAX PopupExtender

Rate me:
Please Sign up or sign in to vote.
2.55/5 (6 votes)
15 Nov 2007CPOL1 min read 50K   23   4
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:

ASP.NET
<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)


Written By
Architect
United States United States
Software Architect

Comments and Discussions

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

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

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