Hi i have a textbox which i am using as a counter to show how many characters are still allowed in another textbox. I have made it read only and its background transparent so that you cant tell it is a select box. The only problem is you can still click on it or tab to it. Is there a way to do this so it appears just like normal text and people cant click on it or tab to it?
Asked
Active
Viewed 2,682 times
1
-
Is there a reason why you have to use a textbox? – Josh Mein Dec 13 '12 at 20:04
-
Why don't you use another control, something like a label or a literal. It would be more appropriate. You would still be able to get and set the value both on the client and server side. – Dec 13 '12 at 20:08
-
I need it to be able to be constantly changed from a client side function. Also i edited the question it is a html textbox. – user1804234 Dec 13 '12 at 20:18
3 Answers
2
If this is an Asp.Net Web Control set it's Enabled
property to false
<asp:TextBox Enabled="false" />
If it is HTML you can do this:
<input type="text" disabled />

hunter
- 62,308
- 19
- 113
- 113
1
you need some style with css and some trick with Jquery.
CSS
.readonly{
border:none;
background:#aaa;
}
Jquery
$(".readonly").focus(function(){
$(this).blur();
});
now just add class="readonly"
to your textbox.
<asp:TextBox cssClass="readonly" />
check demo here .

Behnam Esmaili
- 5,835
- 6
- 32
- 63
1
Just replace the input
element with a span
element or some other non-input element. This requires a trivial change to your JavaScript; you would assign to the innerHTML
property of the element rather than value
. Then the content will appear as normal text, and you can style it as desired.

Jukka K. Korpela
- 195,524
- 37
- 270
- 390