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
  4. This comment has been removed by the author.

    ReplyDelete
  5. As always your articles do inspire me. Every single detail you have posted was great. ExcelR Pune Digital Marketing Course

    ReplyDelete
  6. Your information about asp is really interesting and innovative. Also I want you to share latest updates about asp. Can you update it in your website? Thanks for sharing.

    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery

    ReplyDelete
  7. This article is worthy of recognition and comment. I found this material attention-grabbing and engrossing. This is well-scripted and highly informative. These views appeal to me. This is how real writing is done. Thank you.
    SAP training in Mumbai

    Data Science training in Mumbai Best

    Best Data Science training in Mumbai

    ReplyDelete
  8. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.
    Data Science Institute in Bangalore

    ReplyDelete
  9. Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
    Data Science Certification in Bangalore

    ReplyDelete

Post a Comment