Set text for TextBox of the Password type

Posted on 2006-05-04
Last Modified: 2013-12-03
I'm trying to do the following:

I want to use textbox for a password field, but if the password was previously set, I'd like to show not an empty fields but this circles (or stars on older systems). No matter what I do, the field is initially empty - I don't have round-trips before the intial display, so it gets into the page load, then into the method for populating controls and that's it. I know that I can do it manually, but I would like to use password type as it simplifies typing with showing only circles (*s). How can I put some initial text in to this textbox?

Question by:Yurich
    LVL 8

    Expert Comment

    not sure what you really want but try this

    <INPUT id="txtPwd" style="BORDER-RIGHT: black 1px solid; BORDER-TOP: black 1px solid; FONT-WEIGHT: bold; FONT-SIZE: 10px; BORDER-LEFT: black 1px solid; COLOR: #999999; BORDER-BOTTOM: black 1px solid; FONT-FAMILY: Verdana" onfocus="javascript: value='';" type="password" size="25" value="password" name="txtPwd">
    LVL 21

    Author Comment

    it will work, but i need to do it using controls, like

    <asp:TextBox id = "txtPassword" runat = "Server" TextMode = "Password"></asp:TextBox>

    then in my code behind

    if( ... )
       // ...
       txtPassword.Text = "something"; // here, I want to see 9 circles (or stars) in my password field

    and the one above doesn't work.

    LVL 6

    Expert Comment

    <asp:TextBox id="TextBox1" runat="server" TextMode="Password"></asp:TextBox>
    LVL 6

    Accepted Solution

    Sorry it was not yet complete :-).
    ...and then:

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If not Page.IsPostBack then
               TextBox1.Attributes("value") = "something"
            end if
        End Sub
    LVL 17

    Expert Comment

    impossible... it's for an security rule... you can't assing a text to a password textBox
    LVL 10

    Expert Comment

    why not?

    the_paab solution works without problems!
    LVL 21

    Author Comment

    excellent - I didn't expect it work as if you just add "value" to the HTML code (what I tried before) it complains that there's no such attribute for this control, but it does work.

    Thank you everybody,

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now