I’m wondering why when I disable an asp.net control by jQuery , It doesn’t recognized in Code behind .
For example I disable a TextBox by some thing like this :
$('#txtNumber').attr('disabled', true);
It disabled fine in client-sdide , But it doesn’t recognized in code behind and it has Enabled = true .
I don’t know how to solve this problem .
Edit : I know how to disable the control by jquery and it’s not the case , My question is Why when I disable it in client side , still in code behind it has true enablity ?
The state of the control on server side (enabled/disabled) is taken from viewstate when the postback happens. Disabling the client side input element will mean that whatever value the input has when the form is submitted will not be sent by the browser as part of the postback.
So for an input element disabled means “Do not send in postback”. Changing it on client side will not cause the viewstate to be updated accordingly. If you change it on the server side, the viewstate will have the info that it is disabled, and then that will be persisted netween postbacks