Should I always call Page.IsValid?

前端 未结 3 735
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-08 21:45

I know to never trust user input, since undesirable input could be compromise the application\'s integrity in some way, be it accidental or intentional; however, is there a

3条回答
  •  轮回少年
    2020-12-08 22:04

    I would be the first to tell you that "All input is evil until proven otherwise." However, in this case, I think your friend is mistaken because by his/her logic we could probably come up with a hundred other properties that should be checked or set, even though the defaults are okay.

    Checking Page.IsValid only makes sense if you have a "CausesValidation" scenario - a button that submitted the form has its CausesValidation property set to True. This would automatically call Page.Validate and all Validation controls belonging to the same ValidationGroup would be checked for validity.

    Edit:

    Just checked it using Reflector and the function will always return True if the Page does not have any Validators(ValidatorCollection is null).

提交回复
热议问题