Is there a way in Visual Basic .net to make textboxes uneditable? I have my program reading data from a file and displaying the contents in various textboxes but dont wish to allow the user to be able to edit the contents of said textboxes.

Dani AI

Generated

As discovered, the simplest ways are to set a textbox to read-only or to disable it. Use ReadOnly when you still want the user to be able to select and copy the text (and for HTML forms, to have the value submitted). Use Enabled = False / the disabled attribute when you want to block all interaction and visually gray the control. Each option has tradeoffs — see examples and notes below.

' WinForms (VB.NET)
TextBox1.ReadOnly = True     ' non-editable, selectable/copyable
TextBox1.Enabled = False     ' disabled, not selectable, grayed out
<!-- ASP.NET WebForms -->
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="true" />
<!-- plain HTML -->
<input type="text" value="sample" readonly>
<textarea readonly>sample text</textarea>

<input type="text" value="sample" disabled> <!-- not submitted with form -->

Key notes and gotchas:

  • A disabled input is not submitted with the form. If the server must receive the value on postback, prefer ReadOnly.
  • ReadOnly preserves selection and copy; Enabled = False prevents both.
  • For a static look that remains selectable, set ReadOnly and remove the border (WinForms BorderStyle or CSS for web).
  • Never rely on client-side readonly/disabled for security; always validate/enforce immutability on the server side.

Official references: , TextBox.ReadOnly (ASP.NET WebForms), and the HTML readonly attribute (MDN).

Solved it myself.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.