I have an ASP.NET TextBox
and I want it to be ReadOnly
. (The user modify it using another control)
But when there is a PostBack()
I've had this same issue but using Knockout binding 'enable' and ASP.Net Server Control Text.
This way:
<asp:TextBox ID="txtCity" runat="server" required="required" class="form-control" placeholder="City" data-bind="value: city, enable: !hasZipCode()"></asp:TextBox>
However, when the form was submitted this field value was always empty. This occurred, I presume, because if the control is disabled, it is not persist on the ViewState chain.
I solved replacing bindig 'enable' by 'attr{ readonly: hasZipCode}'
<asp:TextBox ID="txtCity" runat="server" required="required" class="form-control" placeholder="City" data-bind="attr{ value: city, readonly: hasZipCode }">/asp:TextBox>