I have an ASP.NET TextBox
with TextMode
set to as MultiLine
. The content of the TextBox
should be displayed as password instead of plain text.
At same time it is not possible to set TextMode
as both Password
and MultiLine
. Is there any alternative way to achieve this?
2
Answers
You have to "compromise" somewhat here.
So, when the user types, you not see "*", but they will not see what they type.
So, drop in a text box, set mode = "multi-line", and thus this markup:
So, we add a blur to the text, and the result is actually quite nice:
eg this:
If you don’t compromise a bit, then you can find some "messy" JavaScript solutions. However, I think the above works and looks just as well/nice as a password box with "*" anyway.
And such a text box? Well, I have no idea why one wants this (perhaps a screen to send some secret message).
So, try the above, I think it is a "reasonable" solution.
I don’t think there is a non-trivial way to achieve this without finding a low level solution.
When you set the
TextBox.TextMode
asPassword
then it renders an<input type="password"/>
HTML element to the client.When you set the
TextBox.TextMode
asMultiLine
then it renders a<textarea/>
HTML element to the client.The problem is that the
TextArea
HTML element doesn’t support password characters. But there is a reasonable workaround:Using CSS style to blur the
TextBox
characters. First add a new item (Web Forms Server Control) to your project and modifyit so that it looks like:
Build your project. Drag-n-drop the
SecretTextArea
control from VS Toolbox to your web form. The result is:The advantage of this blurring method is that you can see and edit the text. Also you can set the blurring amount by changing the px value in the
text-shadow
attribute.