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?
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.
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
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
is working on a reply...