asp:TextBox ReadOnly=true or Enabled=false?

asp.netTextboxReadonlyDisabled Control

asp.net Problem Overview


What's the difference between the Enabled and the ReadOnly-properties of an asp:TextBox control?

asp.net Solutions


Solution 1 - asp.net

If a control is disabled it cannot be edited and its content is excluded when the form is submitted.

If a control is readonly it cannot be edited, but its content (if any) is still included with the submission.

Solution 2 - asp.net

Another behaviour is that readonly = 'true' controls will fire events like click, buton Enabled = False controls will not.

Solution 3 - asp.net

Readonly will not "grayout" the textbox and will still submit the value on a postback.

Solution 4 - asp.net

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>

Solution 5 - asp.net

Readonly will allow the user to copy text from it. Disabled will not.

Solution 6 - asp.net

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>

Solution 7 - asp.net

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlfView Question on Stackoverflow
Solution 1 - asp.netAdam BellaireView Answer on Stackoverflow
Solution 2 - asp.netrodrigoclView Answer on Stackoverflow
Solution 3 - asp.netBob DizzleView Answer on Stackoverflow
Solution 4 - asp.netCorey TragerView Answer on Stackoverflow
Solution 5 - asp.netJonathan C DickinsonView Answer on Stackoverflow
Solution 6 - asp.netkavitha ReddyView Answer on Stackoverflow
Solution 7 - asp.netGuyView Answer on Stackoverflow