how to lock a textbox

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I have a textbox on a webform and based on certain conditions I wanted to
prevent a user from editing its text. I dont like the look of the texbox
when its disabled and was wondering if there is a different way to lock it
with how hiding it and creating a label to look just like it. I was also
going to do this server side.

Thanks.
 
you can make it readonly.

textbox.Readonly = true;

that will give it the normal look like you can type in it, rather then the
gray look that disabling it does.
 
Hi Moondaddy,

As Mike has suggested, TextBox can be set to readonly mode(in addition to
disabled) which will remain the eabled look style.

===========
<asp:TextBox ID="MyTextbox1" runat="server" ReadOnly=true></asp:TextBox>

<input type="text" readonly="true" />
===================

Does thie fit your scenario?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
you can make it readonly.

textbox.Readonly = true;

that will give it the normal look like you can type in it, rather then the
gray look that disabling it does.
 
That's a step in the right direction, however, I don't want the user to be
able to type in it, otherwise, they will think they are allowed to do so. I
want it read-only - locked similar to a windows textbox. The problem with
setting enabled=false is that the text is not clear and is more difficult to
read.

Thanks.

Steven Cheng said:
Hi Moondaddy,

As Mike has suggested, TextBox can be set to readonly mode(in addition to
disabled) which will remain the eabled look style.

===========
<asp:TextBox ID="MyTextbox1" runat="server" ReadOnly=true></asp:TextBox>

<input type="text" readonly="true" />
===================

Does thie fit your scenario?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no
rights.


--------------------
 
Thanks for your prompt response Moondaddy,

Yes, I know your concern here. And the "readonly" html attribute or
"ReadOnly" server control property does help make the textbox prevent from
user inputting and display readonly content without gray them. Is there
anything else prevent you from using this option?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
Hi Moondaddy,

Any further question on this? If so, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
 
That's a step in the right direction, however, I don't want the user to be
able to type in it, otherwise, they will think they are allowed to do so. I
want it read-only - locked similar to a windows textbox. The problem with
setting enabled=false is that the text is not clear and is more difficult to
read.

Thanks.

You could always Blur() the focus when the focus is set to the
readonly text boxes.

Or just make a CSS class and have a label that *looks* like a textbox.

The problem I see with that you want to do is that it would be
frustrating as a user to have a textbox that looks active that doesn't
let me change it.

My solution would be just to show a label with no textbox look to it.
Just make it static text.
 
Thanks for Larry's input.

Yes, I also agree that it would better we add some indication for the
disabled(but look active) TextBox so as to provide better user experience.
How do you think Moonaddy?

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
Yes you're right, it would be frustrating if the textbox had a read-write
appearance. the Read-Only solution will work fine because when I set it to
Read-Only, I set the background to GhostWhite which is a nice clean light
gray and the text is normal and easy to read.

Thanks.
 
or if its readonly based on conditions, then why not show a label then. Show
a textbox if the person can enter in data, and then show a label if they
can't?

Either way you have to add some logic so adding a label may make it a little
easier for coding purposes.
 
Back
Top