javascript - Enable/Disable aspx Validator via js not holding true in code behind? -


i'd know i'm missing regarding disabling these via js only, , not having add repeat code in code behind.

i'm using code disable / enable validators:

validator: {         enable: function (id) {             console.log('enable',id);             var validator = document.getelementbyid(id);             validatorenable(validator, true);         },         disable: function (id) {             console.log('disable',id);             var validator = document.getelementbyid(id);             validatorenable(validator, false);         }     }, 

it works great, until make postback save data, ... these disabled validators not disabled.

so have run repeated code within onload() if ispostback true disable validators i've disabled via js already.

edit: removed code wasn't required achieve answer. answer: server side must disable elements, can't done explicitly these reasons: found here, @connersfan: https://msdn.microsoft.com/en-us/library/aa479045.aspx

  • some validation controls may not support client scripting. example: if using customvalidator server validation function no client validation function.
  • security considerations. can take page script , disable or change it. should not rely on script stop bad data getting system, provide more immediate feedback users. reason, if using customvalidator, should not provide client validation function without corresponding server validation function.

as can see in asp.net validation in depth, prefered method enable/disable validator on client side use validatorenable:

var validator = document.getelementbyid(id); validatorenable(validator, false); 

on server side, must enable/disable validator explicitely (i don't think can avoid that):

validator.enabled = false; 

this change preserved in client code, unlike change in javascript code not preserved on postback.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -