views:

21

answers:

1

Hi,

I had a dotnet page with some input boxes and a bunch of validators on it that was working fine. However I decided to re-engineer it so that some of the functionality was parcelled up into webcontrols instead.

Now in order to check validation before moving on I'm using Page.IsValid in the button click event, because the button which completes the form is no longer in the same web control as the input boxes. However, even though the validators still work for the webcontrol itself (firing postbacks from other parts of the same webcontrol trips the validators as expected), they still seem to return true for Page.IsValid, even if the content isn't valid.

Webcontrols don't have their own IsValid proprety - why aren't the validators tripping page.IsValid anymore?

A: 

Have you looked at using a ValidationPropertyAttribute on your custom web control class? You can use it to define that some properties require validation.

From MSDN:

[ValidationPropertyAttribute("Message")]
public class MessageControl : Label
{
  private int _message = 0;
  public int Message
  {
    get 
    {
      return _message;
    }
    set
    {
       _message = value;
    }
  }
}

Also see http://msdn.microsoft.com/en-us/library/system.web.ui.validationpropertyattribute.aspx

Dev F