Problem – ASP.net handles textboxes with TextMode = “Password” differently than Classic ASP. In Classic ASP the password would be displayed as masked characters, so for example a six character password would be displayed as six dots in the textbox.
The user could edit the password. When the record was saved, the existing or edited password would be saved. In ASP.net the password characters are not displayed as dots and this is very confusing for users.
This change was made to enhance security when working with passwords. However there are occasions where the level of security is not required.
Background – When TextMode = “Password” is set, the password is not displayed in the textbox even if the Text = “<%# Bind(“Password”) %>. When TextMode=”Password”, the Value property and not the Text property is displayed as masked characters. However,
the Value property is not a default attribute of textboxes and so you can not directly set the value. Many posts exist on how to add the Value Attribute and assign a string, e.g. “myPassword,”, but I could not find a post that could easily add the Value attribute
and its value when the password value is obtained from the FormView’s underlying datasource.
Resolution - The html on the aspx page is shown below. To accomplish my goal, I created a new PasswordValue textbox that is set visible=”false” and its Text="<%# UserPassword %>. The password is not displayed on the Web Page, but the value is exposed
if the user selects View Source. This is the same level of security provided in Classic ASP.
<tr>
<td id="td7" runat="server" class="entryPrompt12"><b>*</b> User Password:</td>
I then add the Value Attribute and the Password text in the tbxePassword_PreRender event on the aspx.cs page event as shown below. The Text value of the PasswordValue textbox is exposed in this event.
DeepPowder
Member
173 Points
359 Posts
ASP.net TextBox.TextMode = "Password' How to enter and edit passwords
Feb 15, 2012 09:51 PM|LINK
Problem – ASP.net handles textboxes with TextMode = “Password” differently than Classic ASP. In Classic ASP the password would be displayed as masked characters, so for example a six character password would be displayed as six dots in the textbox. The user could edit the password. When the record was saved, the existing or edited password would be saved. In ASP.net the password characters are not displayed as dots and this is very confusing for users.
This change was made to enhance security when working with passwords. However there are occasions where the level of security is not required.
Background – When TextMode = “Password” is set, the password is not displayed in the textbox even if the Text = “<%# Bind(“Password”) %>. When TextMode=”Password”, the Value property and not the Text property is displayed as masked characters. However, the Value property is not a default attribute of textboxes and so you can not directly set the value. Many posts exist on how to add the Value Attribute and assign a string, e.g. “myPassword,”, but I could not find a post that could easily add the Value attribute and its value when the password value is obtained from the FormView’s underlying datasource.
Resolution - The html on the aspx page is shown below. To accomplish my goal, I created a new PasswordValue textbox that is set visible=”false” and its Text="<%# UserPassword %>. The password is not displayed on the Web Page, but the value is exposed if the user selects View Source. This is the same level of security provided in Classic ASP.
<tr>
<td id="td7" runat="server" class="entryPrompt12"><b>*</b> User Password:</td>
<td id="td8" runat="server" class="entryValue" >
<asp:TextBox id="tbxeUserPassword" runat="server" Width="100px"
TextMode="Password" CssClass="password12" Text='<%# Bind("UserPassword") %>' onprerender="tbxeUserPassword_PreRender" />
<asp:TextBox ID="tbxePasswordValue" runat="server" CssClass="devTbx100"
Text='<%# Bind("UserPassword") %>' Visible="False" />
</td>
<td></td>
</tr>
I then add the Value Attribute and the Password text in the tbxePassword_PreRender event on the aspx.cs page event as shown below. The Text value of the PasswordValue textbox is exposed in this event.
protected void tbxeUserPassword_PreRender(object sender, EventArgs e)
{
TextBox tbxeUserPassword = (TextBox)FormView1.FindControl("tbxeUserPassword");
TextBox tbxPasswordValue =
(TextBox)FormView1.FindControl("tbxePasswordValue");
string sPasswordValue = tbxePasswordValue.Text;
tbxeUserPassword.Attributes.Add("Value", sPasswordValue);
}
All is done on the entry.aspx and aspx.cs pages, no need to create new dlls.