Why does a read-only textbox not return any data in ASP.NET? Why does a read-only textbox not return any data in ASP.NET? asp.net asp.net

Why does a read-only textbox not return any data in ASP.NET?


There is a little bit of strangeness when it comes to the ASP.NET Readonly property and the readonly attribute of an HTML input element. Rather than setting the Readonly property of the web control try simply adding the HTML attribute to the control like this:

textBox.Attributes.Add("readonly", "readonly");

This will make the control read-only in the client's browser yet still allow you to retrieve the value of the input when it posts back to the server.


The system assumes that read only or disabled controls won't be changed clientside so it doesn't post the changed value back to the server. You need to set the client side readonly property rather than the serverside version.


ASP.NET assumes that the Readonly and Enabled="false" property of the webcontrol will not change . Thus it does not postback the value as mentioned by tom above . You can use this workaround . Adding this to the html you don have to worry about Readonly property or disabled control .

   onkeydown="return false;"