I am assigning a value to .Text of a textbox retrieved from a database in Page_Load() but no characters are shown in the textbox after doing this. The value is indeed there when I try to read from it after the assignment.
I would 开发者_运维技巧like to present some characters to the user even though they are the "dotted" password characters so they know a password has been entered here. Is it possible to do this?
TextBox myTextBox = (TextBox)ControlTextBox;
string pwVal = myTextBox.Text;
myTextBox.Attributes.Add("value", "*******");
Simply put, get a reference to your Textbox, save the password to a value elsewhere in your code, and set the value attribute (since the controls are rendered as an HTML form element anyway) to whatever you want.
You could use JavaScript to do this on the client side once the page loads. However, I'm not so sure you'd want to do this... What kind of page is this, a profile page or something? Maybe you can change it to say "Change Password" or something like that. Otherwise, you'd have to double check to make sure the text entered there isn't the text you prefilled in automatically, etc. and it could lead to some problems.
You can't do that with the Textbox in Password TextMode.
If this is a ready only field, use the default TextMode, and replace all the characters except the last few with asterisks.
If not, display the last few characters in a label next to the password textbox.
精彩评论