Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Mark Olbert 87 posts 117 karma points
    Feb 24, 2010 @ 05:24
    Mark Olbert
    0

    UserControl Validation

    I have a usercontrol which I'm using in a template within Umbraco. I'm having trouble getting the validation to work. I can do validation within the usercontrol, but I also want the template to be able to check to see if the usercontrol "as a whole" is valid.

    To do that I've added the IValidator interface to the usercontrol and implemented ErrorMessage, IsValid and Validate(). They all work fine...when they are called.

    However, if I do a postback from, say, a button on the template which contains the usercontrol, the Validate() method of the usercontrol is not called automatically on postback. Instead, I have to call it manually within the button's click event handler.

    It's not a big deal, but it is annoying. Is there a trick to getting the usercontrol's Validator() method called? Or is that something that doesn't work within masterpages?

    - Mark

  • Richard Soeteman 4046 posts 12899 karma points MVP 2x
    Feb 24, 2010 @ 08:35
    Richard Soeteman
    1

    Hi Mark,

    Validators always a nice thing whith asp.net, not :-( But a maybe a few tips that can help.

    1. Use the BaseValidator class instead of IValidator since all asp.net validators derive from this base class
    2. Use Page.IsValid in the click event handler of your button to trigger the validator
    3. Read this MSDN Article about the BaseValidator Class.

    Hope it helps you,

    Richard

Please Sign in or register to post replies

Write your reply to:

Draft