Textbox Using TextMode Password not Showing Text Asp.Net C#


When the TextMode property of an ASP.NET TextBox is set to Password the value set in the Text property will not display at runtime.

While the security reasons are good to not display the masked password value, leaving it unmasked in the source, it is also necessary at times to display the masked value in the TextBox. 

Security reasons aside, you can work around this by adding the password value to the control as as Attribute. Since the TextBox renders as an HTML input control, you can set the value attribute easily, just as you would set the Text property.

       Html Coding
  <html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
            <asp:Label ID="Label1" runat="server" Text="UserName"></asp:Label>
                <asp:TextBox ID="txtUsername" runat="server"></asp:TextBox>
            <asp:Label ID="Label2" runat="server" Text="Password"></asp:Label>
                <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox>
        <tr><td colspan ="2">
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Login" />


First Add  - Web Form - Select Label & Textbox & Button From ToolBox - Design  Username & Password  - Change the Id  & Go to - Property - TextMode = Password Change

                               Html Page  


   Next - F5 Click - Run   Program  -  Enter Username & Password (Hide ) 



Post a Comment