Force password field to retain value after postback

Posted on 2006-04-16
Last Modified: 2011-10-03
This might be more a javascript question but...

I''m handling a login submission at a point where the user has submitted the form (contains a TextMode=password field) once already on just needs to verify info in the email field. How do I re-populate the password field with the original value?
Question by:juststeve
    LVL 1

    Accepted Solution

    Here is an example of a way to accomplish what you are trying to do:

    ASPX Page
    <html xmlns="" >
    <head runat="server">
        <title>Untitled Page</title>
        <script type="text/javascript" >
             function setPassword(password){
                var txtPassword = document.getElementById("txtPassword");
                txtPassword.value =password;
    <body >
        <form id="form1" runat="server">
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox></div>
         <asp:Literal ID="scriptPlace" runat="server"></asp:Literal>


    // Substitue 'this' as a variable with your data
    protected void Page_Load(object sender, EventArgs e)
            this.scriptPlace.Text = "<script type='text/javascript'>setPassword('this');</script>";

    Author Comment

    Not sure if this is a C# vs VB issue but I had to use:

    Me.scriptPlace.Text = "<script type='text/javascript'>setPassword('" & myPassHolder & "');</script>"

    Other than that, worked great, thx!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    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.…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now