I have a form with a number of asp:TextBoxes. The user is able to edit the text within these text boxes, and when the ‘SAVE’ button is pressed, these new values are written to a database.
I have 3 text boxes in total, and the first 2 text boxes’ new values are passed on to the code behind without any problem. However, the 3rd text box’s old content is passed onto the server, rather than the user-edited data.
The markup for the problematic textbox is shown below:
<asp:TextBox ID="descriptionBox" ReadOnly="true" style" runat="server" TextMode="MultiLine" Text='<%# Eval("Description") %>'></asp:TextBox>
The following is the C# code which attempts to get the contents of the text box after the user has edited it. Please note that these text boxes are placed in a Repeater:
string description = ((TextBox)e.Item.FindControl("descriptionBox")).Text;
Could anyone suggest what the problem could be? The other text boxes use the same exact markup and code, and they work just fine.
See the MSDN documentation – it’s the ReadOnly attribute causing this problem:
The alternative is to do it on the client side:
descriptionBox.Attributes["readonly"] = "readonly"