Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 15, 2012 09:51 PM by DeepPowder
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.
<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" />
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 =
string sPasswordValue = tbxePasswordValue.Text;
All is done on the entry.aspx and aspx.cs pages, no need to create new dlls.