Disable some ASP.Net validation controls when a checkbox is checked

后端 未结 3 567
挽巷
挽巷 2021-02-06 01:25

I\'m using old fashioned ASP.NET validation (ugh) for a checkout process. I have a checkbox -\"I\'ll call with my credit card details\"-. If checked I need to disable the requir

相关标签:
3条回答
  • 2021-02-06 01:32

    You can disable the validators client-side (in javascript):

    function disable(validatorId)
    {
       var validator = document.getElementById(validatorId);
       ValidatorEnable(validator, false);
    }
    

    Where validatorId is the clientID of the validator to be disabled. See this page for a complete example.

    0 讨论(0)
  • 2021-02-06 01:36

    You can disable the validators server-side:

    MyFieldValidator.Enabled = MyCheckBox.Checked
    
    Page.Validate()
    If Page.IsValid Then
       'stuff
    end if
    
    0 讨论(0)
  • 2021-02-06 01:57

    If you're disabling server side then you can do

    button1.CausesValidation = False
    

    in your CheckChangedEvent this is more helpful if you have a lot of validators and need to disable them all.

    0 讨论(0)
提交回复
热议问题