Asp.Net Validators Incompatible with SharePoint controls

On a recent project I learned the hard way that the Asp.Net validator controls like RequiredFieldValidator or RangeValidator do not work with the Microsoft.SharePoint.WebControls controls. For this reason you will frequently need to create your own validation logic when working with controls from this SharePoint namespace. When using Reflector to inspect the type of the ControlToValidate field used in the Asp.Net validators, it appears that it is looking for a control of type System.Web.UI.WebControl. Interestingly, in Reflector the DateTimeControl appears to have its own RequiredFieldValidator in its child controls that is enabled when the IsRequiredField="true" attribute is set. It is also important to note that SharePoint also provides some validators within the Microsoft.SharePoint.WebControls namespace including the InputFormRequiredFieldValidator or InputFormRangeValidator, but even these are incompatible with some of the other SharePoint controls.
So an important question that comes up is what is the best way to handle validation on SharePoint controls. A couple of different approaches can be taken. One would be to derive from the existing validator controls and to expect that a control of type Microsoft.SharePoint.WebControls.SPControl. Another approach would be to emulate the functionality of the System.Web.UI.WebControls behavior by using a label and then calling the validation logic. The primary gotcha that was encountered with this second approach was that the convenience of calling Page.Validate() will unfortunately invoke the built-in SharePoint control validation which may or may not fulfill your application requirements.

3 thoughts on “Asp.Net Validators Incompatible with SharePoint controls

Add yours

  1. Man, I hear this stuff all the time. I just don’t get why people are so strong on WSS and MOSS, or why MS doesn’t align them more with standard ASP.NET.++Alan

  2. I’m not sure i got what you are trying to explain, but i’ve used SharePoint with validator controls just fine, especifically with InputFormRequiredFieldValidator, wich i’ve tested with textbox, and some other SharePoint controls, maybe the problem was elsewhere

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: