What's the difference between the Enabled and the ReadOnly-properties of an asp:TextBox control?
This question is related to
asp.net
textbox
readonly
disabled-control
Readonly will allow the user to copy text from it. Disabled will not.
Readonly textbox in Asp.net
<asp:TextBox ID="t" runat="server" Style="margin-left: 20px; margin-top: 24px;"
Width="335px" Height="41px" ReadOnly="true"></asp:TextBox>
Another behaviour is that readonly = 'true'
controls will fire events like click
, buton Enabled = False
controls will not.
Readonly will not "grayout" the textbox and will still submit the value on a postback.
Think about it from the browser's point of view. For readonly the browser will send in a variable/value pair. For disabled, it won't.
Run this, then look at the URL after you hit submit:
<html>
<form action=foo.html method=get>
<input name=dis type=text disabled value="dis">
<input name=read type=text readonly value="read">
<input name=normal type=text value="normal">
<input type=submit>
</form>
</html>
I have a child aspx form that does an address lookup server side. The values from the child aspx page are then passed back to the parent textboxes via javascript client side.
Although you can see the textboxes have been changed neither ReadOnly or Enabled would allow the values to be posted back in the parent form.
Think about it from the browser's point of view. For readonly the browser will send in a variable/value pair. For disabled, it won't.
Run this, then look at the URL after you hit submit:
<html>
<form action=foo.html method=get>
<input name=dis type=text disabled value="dis">
<input name=read type=text readonly value="read">
<input name=normal type=text value="normal">
<input type=submit>
</form>
</html>
Readonly textbox in Asp.net
<asp:TextBox ID="t" runat="server" Style="margin-left: 20px; margin-top: 24px;"
Width="335px" Height="41px" ReadOnly="true"></asp:TextBox>
Readonly will allow the user to copy text from it. Disabled will not.
Readonly will not "grayout" the textbox and will still submit the value on a postback.
Another behaviour is that readonly = 'true'
controls will fire events like click
, buton Enabled = False
controls will not.
Readonly will allow the user to copy text from it. Disabled will not.
I have a child aspx form that does an address lookup server side. The values from the child aspx page are then passed back to the parent textboxes via javascript client side.
Although you can see the textboxes have been changed neither ReadOnly or Enabled would allow the values to be posted back in the parent form.
Readonly will allow the user to copy text from it. Disabled will not.
Think about it from the browser's point of view. For readonly the browser will send in a variable/value pair. For disabled, it won't.
Run this, then look at the URL after you hit submit:
<html>
<form action=foo.html method=get>
<input name=dis type=text disabled value="dis">
<input name=read type=text readonly value="read">
<input name=normal type=text value="normal">
<input type=submit>
</form>
</html>
Think about it from the browser's point of view. For readonly the browser will send in a variable/value pair. For disabled, it won't.
Run this, then look at the URL after you hit submit:
<html>
<form action=foo.html method=get>
<input name=dis type=text disabled value="dis">
<input name=read type=text readonly value="read">
<input name=normal type=text value="normal">
<input type=submit>
</form>
</html>
Readonly will not "grayout" the textbox and will still submit the value on a postback.
Source: Stackoverflow.com