Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net: gray out a textbox with enabled = false, but need to get the value

I want to disable a textbox for a user.

But in the textbox is a value, that I need to read.

So I want the readOnly property (because I can read the value), but also want to gray out the box (function of enabled = false), that the user can see, he hasn't access to edit the textbox.

Which is the best way to do this?

like image 672
Keith L. Avatar asked Apr 17 '12 07:04

Keith L.


People also ask

How do I GREY out a TextBox in asp net?

You can gray out the text box by changing its background color. Save this answer. Show activity on this post. Use Label instead, why you are using TextBox if you want to open edit for user, also change the color of the Label control.

How do I gray out a TextBox in HTML?

The disabled="disabled" parameter is the standard way to do this, and you could use something like jQuery to dynamically disable all of the form elements contained in a fieldset (Which is the standard way of grouping related form elements) on the fly.


2 Answers

if your text box is a html input text so do this:

    <input id="Text1" type="text" value="read me"  readonly="readonly" disabled="disabled" />

and if it's an asp TextBox then:

    <asp:TextBox ID="TextBox1" runat="server"  ReadOnly ="true" Enabled="false"></asp:TextBox>
like image 124
st mnmn Avatar answered Oct 14 '22 20:10

st mnmn


@Keith setting Readonly attribute to input box will be good. You can gray out the text box by changing its background color.

like image 34
naim shaikh Avatar answered Oct 14 '22 19:10

naim shaikh