TextBox-TextMode

S

Stephen McCrea

I have been trying to implement a password text box in a datagrid using a
template column.

When I set the TextBox.TextMode = Password nothing is displayed but when I
set it to SingleLine I see the password in plain text.

Is there some way to have the 'Password' behaviour in a data grid control
text box?

Thank you,
 
S

Sandeep Kayal

You can do this by using a template column.
" <asp:TemplateColumn HeaderText="Advance Amount"
Itemstyle-HorizontalAlign="Right" HeaderStyle-Width="80px"
SortExpression="AdvanceAmount">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center"
ForeColor="White"></HeaderStyle>
<ItemTemplate> <%#Container.DataItem("passwordField")%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtPassword" Runat="server" MaxLength="10"
Width="60px" TextMode=Password></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn> "

In Itemdatabound of the grid you can get the value as follows:
Dim objDrv As DataRowView

objDrv = CType(e.Item.DataItem, DataRowView)

Dim strPassword As String

strPassword=objDRV("PasswordField")

Dim objTxtPasswordField As TextBox = e.Item.FindControl("txtPasswordField")

If Not objTxtPasswordField Is Nothing Then objTxtPasswordField.Text =
strpassword

Hope this helps

Thanks,

Sandeep
 
S

Stephen McCrea

I tried a template column and it does not display text when in 'password'
mode. The text box is completely empty!

If I re-compile in SingleLine mode it shows the password.

Is it necessary to specify a replacement character somewhere?

The following is cut from my HTML:

<asp:TemplateColumn HeaderText="Password">
<ItemTemplate>
<asp:TextBox id=TextBox1 runat="server" ForeColor="Black" Text='<%#
DataBinder.Eval(Container.DataItem, "Password") %>' ReadOnly="True"
TextMode="Password">
</asp:TextBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id=TextBox2 runat="server" ForeColor="Black" Text='<%#
DataBinder.Eval(Container.DataItem, "Password") %>' TextMode="Password">
</asp:TextBox>
/EditItemTemplate>
</asp:TemplateColumn>


Thank you,
 
S

Stephen McCrea

When I single step the Update command I see the password data contained in
the TextBox.Text field even though it is not displayed (i.e, as a sequence
of replacement characters) in the interface when TextMode=Password.
 
S

Sandeep Kayal

Hi stephen,

This wont show anything written inside EditItemTemplate since Readonly is
set to true. Try setting Readonly to false in ItemTemplate

Sandeep
 
S

Stephen McCrea

IMHO: The password textbox should display the password as a sequence of
characters like '*'. It should work properly, like a password textbox in a
form. (It must be a bug)

To maintain a more normal look and feel, what I have done is to use a label
in the ItemTemplate with '********' in its text field and a password textbox
in the EditItemTemplate bound to the data item.

The password can be changed during edit mode in the unfortunately blank
textbox. While typing the new password, only the mask characters are visible
and not the actual characters.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top