How to assign a default value to a Password Control in ASP.NET

Dec 16, 2009 Posted by Lara Kannan
If you set the TextMode property of a TextBox Web control to "Password" any default value you assign to the TextBox won't show up.

To work around this problem, add the following code to your ASP page:

There are two ways to initialize a TextBox whose TextMode is "password" with a default password:

Method 1 :-
<asp:TextBox TextMode="Password" id="txtPwd" RunAt="server"/>

<script language="C#" runat="server">
void Page_Load (Object sender, EventArgs e)
{
txtPwd.Attributes.Add ("value", "MyPassword");
}
</script>

Method 2 :-
<asp:TextBox Value="MyPassword" TextMode="Password" id="txtPwd" RunAt="server"/>

Happy coding!

Share
Labels: ,

Post a Comment