Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp:textbox readonly

In asp file I have two asp:textbox

<asp:TextBox ID="textValue" runat="server" Width="100px"/>
<asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true"/>

then I set the value via javascript getting

<asp:TextBox ID="textValue" runat="server" Width="100px" value="aaa"/>
<asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true" value="bbb"/>

but when refresh the webpage finally get

<asp:TextBox ID="textValue" runat="server" Width="100px" value="aaa"/>
<asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true"/>

Why the value bbb is "lost"? How can I avoid this?

like image 361
Dr. No Avatar asked May 03 '11 13:05

Dr. No


People also ask

Which data controls are read-only in asp net?

Enabled TextBox and ReadOnly TextBox ASP.Net TextBox control has similar two properties “Enabled” and “ReadOnly”. Both properties used to prevent a user from entering a value in textbox. The Enabled and ReadOnly make textbox field non-editable mode.

How do you make a TextBox non editable in asp net?

Add("readonly", "readonly"); From MSDN, The Text value of a TextBox control with the ReadOnly property set to true is sent to the server when a postback occurs, but the server does no processing for a read-only text box.

What is the Read-only in the TextBox?

Definition and UsageThe readonly attribute is a boolean attribute. When present, it specifies that an input field is read-only. A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).

How do I make a TextBox read-only in asp net?

Use the ReadOnly property to specify whether the contents of the TextBox control can be changed. Setting this property to true will prevent users from entering a value or changing the existing value. Note that the user of the TextBox control cannot change this property; only the developer can.


1 Answers

<asp:TextBox ID="textValue2" runat="server" Width="100px" ReadOnly="true"/>

You are missing a quotation mark before 'true', it might cause issues.

like image 169
Tom Gullen Avatar answered Oct 11 '22 04:10

Tom Gullen