Pre-filling a TextBox control with TextMode=”Password”

When the TextMode property of a TextBox control is set to Password, the value you assign to the Text property (either declaratively or programmatically) isn’t actually displayed at runtime, not even in masked mode (with the * chars). This is of course done for security reasons, because even if the password would be shown in masked mode, the actual clear-text password could still be retrieved from the page’s source HTML code.

However, there are times when you actually want to pre-fill the password field, for example in a “My Profile” page where the user can change his personal data, including his account’s password. If you don’t protect very sensitive information, you may decide that showing the password in masked mode is a good compromise to increase the user’s experience. (The option of not showing the password at all and only update the password if the user types in something is not as intuitive for the user…). It would have been nice to have a direct option to show the password in masked mode but, as said, nothing appears if you set the TextBox’s Text property. The trick is very simple though: you just have to manually add a “value” attribute to the HTML generated by the server-side textbox control, where the value is the password. You do this by accesing the control’s Attributes collection, as shown below:

PasswordField.Attributes.Add("value", "secret")

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS