I was reading about the difference between Disabled vs Read only and I learned that with a disabled field the data is not send back on postback. However I have a webforms page with a textbox like below:
<asp:TextBox runat="server" ID="vPlantNameTB" Text="" Enabled="false"></asp:TextBox>
On page load I set the value of vPlantNameTB
to some value. (instead of blank).
Since I have this TextBox disabled. I expect the value of the TextBox to be blank on post-back. But that is not the case...
I am able to get the value I set it to on page load during post-post back.
Is this behavior normal for web-forms?
In short:
yes, because the value is coming from your viewstate, not the form.
For a slightly more involved answer...
The form data that gets submitted (accessible through Request.Form
) will be missing for vPlantNameTB
as it is disabled and therefore not sent by the browser to the server.
Also included in the form data sent to the server is a hidden input (generated by the .Net engine) called __VIEWSTATE
and it's value is a base64-encoded string that represents the current state of the page.
The page state automatically serialized out to the rendered web page and automatically deserialized when the form is posted (the deserialization process also handles re-association with your page controls which is why vPlantNameTB
has a value again in your postback handler).
Scott Mitchell has a decent article about ViewState on MSDN which describes the process quite well.