I have an asp.net textbox which is disabled and I am setting the value for the textbox on client side using JQuery.
$('[id$=txtCity]').val('Naperville');
But the problem is when I am trying to save the data. If I say txtCity.Text it is not giving me the value that I set in the client side.
The textbox is disabled and I am seeing the value reflected in the textbox on the client side after the value is set using JQuery. But I am not sure why it is not reflected on the server side.
I found that TextBox with disabled will not be submitted with the form on postback. If that is true, how can I submit those values and get that on server side in the code behind.
Please help. Thanks and appreciate your feedback.
You can always “un-disable” the field before posting. E.g.,
And of course using
readonlyfields, as per Knix’s answer, may be a viable solution as well.Edit: just read your comment on Knix’s answer, so it sounds like dynamically removing the disabled attribute before posting may be the way to go.