News

Laurent Kempé MVP
PDC 2008

Contact

My status

View Laurent Kempé's profile on LinkedIn
XING
twitter
facebook


Xbox 360



Map

Locations of visitors to this page

.NET Dudes

Family

French .NET Dudes

Friends

Links

Tech Head Brothers

ASP.NET AJAX and ASP.NET Validators

If you are using ASP.NET Validators in UpdatePanel consider the post of Matt Gibbs : "ASP.NET AJAX Validators".

ASP.NET AJAX provides new APIs for registering script with the ScriptManager.  Using these APIs allows controls to work well with partial rendering.  Without them, controls placed inside an UpdatePanel won't work as expected. In previous CTP releases of ASP.NET AJAX, we had a set of validator controls that derived from the v2.0 controls and used the new APIs. This made them work well with ASP.NET AJAX. WindowsUpdate will soon include a version of System.Web that can take advantage of the new APIs.  So the new controls which would have been redundant have been removed.  However, the update isn't available yet and ASP.NET AJAX has been released.  So, in the short-term, the source code for a set of custom validator controls that work with partial rendering is available here.

The .zip file includes a solution and .csproj file as well as the compiled DLL.  Just put the DLL in the /bin directory of your application and include the following <tagMapping section in the pages section of the web.config.

      <tagMapping>
        <add tagType="System.Web.UI.WebControls.CompareValidator"           mappedTagType="Sample.Web.UI.Compatibility.CompareValidator, Validators, Version=1.0.0.0"/>
        <add tagType="System.Web.UI.WebControls.CustomValidator"            mappedTagType="Sample.Web.UI.Compatibility.CustomValidator, Validators, Version=1.0.0.0"/>
        <add tagType="System.Web.UI.WebControls.RangeValidator"             mappedTagType="Sample.Web.UI.Compatibility.RangeValidator, Validators, Version=1.0.0.0"/>
        <add tagType="System.Web.UI.WebControls.RegularExpressionValidator" mappedTagType="Sample.Web.UI.Compatibility.RegularExpressionValidator, Validators, Version=1.0.0.0"/>
        <add tagType="System.Web.UI.WebControls.RequiredFieldValidator"     mappedTagType="Sample.Web.UI.Compatibility.RequiredFieldValidator, Validators, Version=1.0.0.0"/>
        <add tagType="System.Web.UI.WebControls.ValidationSummary"          mappedTagType="Sample.Web.UI.Compatibility.ValidationSummary, Validators, Version=1.0.0.0"/>
      </tagMapping>

Comments

mhawley said:

The RTW doesn't require this anymore. This info is outdated.

# March 26, 2007 9:07 PM

mhawley said:

Ohh nevermind :) Now I see the additional download! Do'h

# March 26, 2007 9:08 PM

lkempe said:

mhawley: It's absolutely NEEDED!!!! with RTW.

# March 27, 2007 12:50 AM

Richard said:

"WindowsUpdate will soon include a version of System.Web that can take advantage of the new APIs."

Two months and still no update? I don't like their definition of "soon"!

# March 28, 2007 7:54 PM

Robby said:

I am using dotnetnuke.  I have placed the validators.dll in my bin, and added the tagging to my web.config.  The validator now works but only when I'm logged in to my app as a registered user.  Is there any special authentication or permission required for these compatible validators to work?

# April 15, 2007 6:21 PM

lkempe said:

Robby: it is working ok here without any fancy settings.

# April 16, 2007 3:18 AM

Marc Brooks said:

This only works for declaratively added validators!  The Tag mapping is used only for the ASPX code generation/compile phase and DOES NOT help for validators you add programmatically.  What we need until the "shortly" passes is a way to sniff that section of the configuration to do the remap when injecting validators.

A better stop-gap would probably be to add an Adapter that does the right thing...

# April 28, 2007 1:46 AM

lkempe said:

Marc: Right I used it only declaratively!

# April 28, 2007 3:54 AM

Rob Meade said:

I am also suffering from the same problem, I have controls which are programmatically created and since adding the .dll to the bin directory and the tagMapping they are just completely ignored, two of my other pages in the same app which have the controls which were dragged and dropped to the page work fine.

What was interesting was prior to doing the above, half of my original validators worked!  I have 2 drop down lists and a validator next to each one, the first validator worked fine and as it should, the second one fired, ie, the submit button wouldn't take you on, but the image (which I'd added as "Text" for the validator) just didn't appear on the page.

Well odd...not sure what to do now - it seemed for me I was closer prior to using the above, as I've been working on this since October and see no obvious end to my project perhaps I should revert back and just hold out for the official fix to the problem?

# May 21, 2007 5:20 AM

John Bailey said:

Can't you use dynamically thus?: Dim requiredValidator As New Sample.Web.UI.Compatibility.RequiredFieldValidator
# June 11, 2007 6:30 AM

Tauqir Malik said:

I downloaded the zip files and added the dll in my project bin directory and added the tagMapping in web.config. I am using formview inside an update panel. But my problem is not resolved still. I have downloaded the update patch recommended Mr. Matt Gibs site from microsoft. I think validator.dll is not compatible after the path is installed. Can anyone help in this regard.

# July 18, 2007 12:35 PM

Haroon Malik said:

Same problem here. I am using a MultiView control inside the UpdatePanel. Did as instructed - placed the DLL in \bin and added the <tagMapping> configuration to Web.Config - but it's not working.

# July 22, 2007 4:30 AM

Haroon Malik said:

Related to my previous comment: I have found out the reason why the Validation controls were not working in the UpdatePanel. It is because of the ValidationGroup property. I had had grouped my validators for the UpdatePanel by setting their ValidationGroup property to prevent them from validating their connected controls with the other validators on the page. However, it is surprising to see that there is no need to set the ValidationGroup property for controls if being placed in an UpdatePanel. Removing the ValidationGroup property solves the problem and the validators work fine.

# July 24, 2007 1:47 PM

lkempe said:

Haroon MAlik: Thansk for the feedback it might help others.

# July 24, 2007 3:51 PM

Tauqir Malik said:

Haroon Malik, thank you for your update and help. My scenario is bit different. I have two Form controls in two different update panels (either the update pannels are nested or separate). It is a 1 to many relationship. So I had to separate the validators by using the ValidationGroup. But I think this is the bug in the API. As there will be scenarios where you would like to separate your validators. Anyway I have to come up with some different logic to overcome the problem. Again Thanks.

# July 28, 2007 12:00 PM

Diogo said:

Haroon Malik,

Thanks, problem solved now.

But why setting ValidationGroup causes these problems?

There is a way to make validators works setting up a ValidationGroup?

Matt Gibbs Solution doesn't work for me. But removing ValidationGroup does...

# August 16, 2007 1:18 PM

Zeeshan said:

RegularExpressionValidator ErrorMessage is not displayed.... just blink for once...

# August 20, 2007 9:07 AM

Dani said:

I've got aproblem with validators using the <tagMapping....

I'm doing a composite control in C# with a requiredFieldValidator and it works with AJAX, and when the page goes to the server, the errorMessage and te Text of the validator doesn't show, only appear in a SummaryValidator, I lose the messageError and the text of the validator.

Thanks.

# September 21, 2007 4:35 AM

John said:

Thanks a million. Solved my problem on the server.

# October 15, 2007 11:30 PM

Ingrid said:

This worked for me. The validators work when I submit the page, or if I enter a bad value after the updatePanel has posted back. However I need the validators to keep their states (show their error messages or not) after UpdatePanel Post Back. That is:

I have a DropDownList on my UpdatePanel that does a postback. All the already validated controls values/states disappear. The validators still work, when I re-trigger them so to speak.

# December 12, 2007 4:56 PM

DEEPAK GUPTA said:

I am using a Repeater control inside the UpdatePanel. Did as instructed - placed the DLL in \bin and added the <tagMapping> configuration to Web.Config - but it's not working.

Pls help

# January 14, 2008 8:45 AM

Jim said:

Hey, thanks for the info.  Just spent about 4 hours trying to figure this out. this solution seems to work perfectly

# January 15, 2008 5:30 PM

lalitha said:

Thank you friend.

It is working fine.

lalitha

# February 26, 2008 5:29 AM

Gene said:

I copied the dll to bin folder and do the same to webconfig, other validator are working fine except validationsummary, after clicking submit button, validationsummary shows multiple times of errormessage. It looks like whenever i do a partial postback with an updatepanel, the summary shows once more. For example, if partial postback twice, then the error message will be displayed twice. It is really weird, any ideas?

# February 27, 2008 4:24 PM

bindu said:

Thanks Marc Brooks. I was really struggling with this problem. Now its solved.

# June 12, 2008 12:47 AM

Puran said:

Thanks, It was giving me great headache. Thank you again for the solution!

# September 27, 2008 9:42 AM

blue.nodule said:

I've included the dll and updated the web.config.  I'm still stuck with the same issue i.e.

Validators in a ModalPopupExtender control.

Validators work fine.  As soon as i press OK with valid info the form doesn't post.

Any ideas guys?

# November 3, 2008 6:07 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)