Skip to main content

show password option in asp.net using checkbox

Show password option for the Password field can be obtained by placing the checkbox and using some piece of JavaScript code to obtain this functionality. This can be done in onchange or onclick events of the checkbox. Find the example below.

ASPX code: Using onchange Event


<html>
<head runat="server">
    <title>Show password checkbox</title>
</head>
<body>
    <form id="form1" runat="server">
      <div><br />
         <asp:Label ID="Label1" runat="server" Text="User name:">
         </asp:Label><asp:TextBox ID="Uname" runat="server"></asp:TextBox>
         <br />
         <asp:Label ID="Label2" runat="server" Text="Password :"></asp:Label>
         <asp:TextBox TextMode="Password" ID="password" runat="server"></asp:TextBox>
         <input type="checkbox" onchange="document.getElementById('password').type = this.checked ? 'text' : 'password'">
            Show password
       </div>
    </form>
</body>
</html>


[OR]


ASPX code: Using onclick Event

<html>
<head runat="server">
    <title>Show password checkbox : fourthbottle</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
          Password :
          <input type="password" name="password" id="password" />
          <input type="checkbox" id="pass" onclick="showpass(this);" />
           Show Password
            <script type="text/javascript">
                function showpass(check_box) {
                    var spass = document.getElementById("password");
                    if (check_box.checked)
                        spass.setAttribute("type", "text");
                    else
                        spass.setAttribute("type", "password");
                }
           </script>
        </div>
    </form>
</body>
</html>


-Anantha Bharani Guhan

Comments

  1. Great Article. Thank you for sharing! Really an awesome post for every one.

    IEEE Final Year projects Project Centers in Chennai are consistently sought after. Final Year Students Projects take a shot at them to improve their aptitudes, while specialists like the enjoyment in interfering with innovation. For experts, it's an alternate ball game through and through. Smaller than expected IEEE Final Year project centers ground for all fragments of CSE & IT engineers hoping to assemble. Final Year Project Domains for IT It gives you tips and rules that is progressively critical to consider while choosing any final year project point.

    Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Spring Framework Corporate TRaining the authors explore the idea of using Java in Big Data platforms.
    Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai

    ReplyDelete
  2. keep up the good work. this is an Assam post. this to helpful, i have reading here all post. i am impressed. thank you. this is our digital marketing training center. This is an online certificate course
    digital marketing training in bangalore | https://www.excelr.com/digital-marketing-training-in-bangalore

    ReplyDelete
  3. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!
    data analytics course
    business analytics course
    data science courses

    ReplyDelete

Post a Comment