Validation and InvalidState

2 posts, 0 answers
  1. Jerome
    Jerome avatar
    87 posts
    Member since:
    Aug 2010

    Posted 01 Dec 2011 Link to this post

    I'm trying to find the proper way to deal with Validation, either using RequiredFieldValidator, RegularExpressionValidator, or a CustomValidator. When one of these validators hooked up to a Telerik RadInput control fails, I'd like the control to switch to it's Invalid State, showing the warning, etc. I can't find anyway to do this. 

    [EDIT]

    I've managed to figure out how to use RadInputManager to validate some of my textboxes... except that it doesn't seem to be invoked during Page.Validate(group), even if I set a group on the TextSetting. It seems like the TextSetting isn't actually added to the Control hierarchy, and so is never located. It also only has a single ErrorMessage property, which makes it impossible to actually specify different message for different inputs, even if their behaviors are the same: First name is required, last name is required, foo is required, blah is required, etc.

    So other than setting the Invalid state of the controls... I can't figure out how this makes things EASIER?
  2. Jerome
    Jerome avatar
    87 posts
    Member since:
    Aug 2010

    Posted 02 Dec 2011 Link to this post

    Solved this, idiotically. This begs for a cleaner solution inside RadInputControl.

    I've created a class, RadInputValidationDecorator, which inherits from Control. It internally creates a CustomValidator subclass, which invokes a JS function on validation. This validation function is always valid. Instead, it loops over the target controls' Validators array, and checks isvalid on each object. If any are invalid, it sets ._invalid to true on the RadInput, and then .updateCssClasses(). This causes the appearence change I'm looking for. It also does the same on the server side, on PreRender, it checks whether all associated Validators (other than itself) with the RadInput are valid, if not, it injects some JS which sets _invalid on the client side when the page is first loaded.

    My solution relies on the Decorator being created and added to the Controls collection AFTER all other validators for the control, otherwise it's validation logic will be fired before the other validators have had a chance to set their 'isvalid' value. This is kind of hacky, but I can't figure out any other way to inject myself into the client side validation logic. 

    I guess I could have javascript that resorts Page_Validators and control.Validators on load. Sounds even more hacky, but is probably the only real solution.

    This is hacky and lame. A RadInput control should be smart enough to change it's own state to invalid when a validator hooked up to it fails. What I ended up doing is something the RadInput itself could do, perhaps by adding itself to it's own Validators collection, to participate in Page validation, or something.

    Anyways, problem sort of solved.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top