How to set Displayformat for a password field?

Last post 05-22-2009 12:52 AM by venkatesh.g2. 9 replies.

Sort Posts:

  • How to set Displayformat for a password field?

    05-20-2009, 6:12 AM
    • Member
      1 point Member
    • venkatesh.g2
    • Member since 05-18-2009, 9:05 AM
    • Posts 7

    Hi,

     I have a password field in the user table. While Insert/Edit the password should display stars (*****). May I know how to set the password field so that it displays only Stars (****) in Insert/edit/list.

    Regards

    Venkatesh G

  • Re: How to set Displayformat for a password field?

    05-20-2009, 7:14 AM
    Answer
    • Star
      12,112 point Star
    • sjnaughton
    • Member since 04-29-2008, 5:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,535
    • TrustedFriends-MVPs

    Well here you go for Edit/Insert mode try this: 

    [MetadataType(typeof(EmployeeMD))]
    public partial class Employee
    {
        public class EmployeeMD
        {
            public object EmployeeID { get; set; }
            public object Name { get; set; }
            [DisplayName("Password")] //makes column title not split
            [DataType(DataType.Password)]
            public object password { get; set; }
        }
    }
    and in Text_Edit.aspx.cs add this to the Page_Load: 
    var password = Column.Attributes.OfType<DataTypeAttribute>().FirstOrDefault();
    if (password != null && password.DataType == DataType.Password)
    {
        TextBox1.TextMode = TextBoxMode.Password;
    } 

    You will need to do something a bit more in the Text.ascx FieldTemplate.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: How to set Displayformat for a password field?

    05-20-2009, 9:12 AM
    • Member
      1 point Member
    • venkatesh.g2
    • Member since 05-18-2009, 9:05 AM
    • Posts 7

    This works correctly while inserting new records but while editing, the existing value is empty. It should show ***** and if I update the old values should not change.

  • Re: How to set Displayformat for a password field?

    05-20-2009, 12:24 PM
    Answer
    • Star
      12,112 point Star
    • sjnaughton
    • Member since 04-29-2008, 5:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,535
    • TrustedFriends-MVPs

    venkatesh.g2:
    It should show ***** and if I update the old values should not change

    surely if you change the value in edit mode and save the value should change?
    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: How to set Displayformat for a password field?

    05-20-2009, 1:16 PM
    Answer
    • Star
      12,112 point Star
    • sjnaughton
    • Member since 04-29-2008, 5:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,535
    • TrustedFriends-MVPs

    venkatesh.g2:
    It should show *****

    I've tested a standard textbox set to password mode and is show no text in edit mode Sad this seems to be normal behaviour.
    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: How to set Displayformat for a password field?

    05-20-2009, 3:03 PM
    • Star
      12,112 point Star
    • sjnaughton
    • Member since 04-29-2008, 5:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,535
    • TrustedFriends-MVPs

    Just did a quick article here: Password FieldTemplates for Dynamic Data

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: How to set Displayformat for a password field?

    05-21-2009, 1:28 AM
    • Member
      1 point Member
    • venkatesh.g2
    • Member since 05-18-2009, 9:05 AM
    • Posts 7

    Hi Steve, 

    The new control is also having the same problem in the EDIT mode.

    1. It show no text in edit mode (As you mentioned, may be this is normal behaviour. Ok I shall accept this)

    2. If you click on update hyperlink from edit mode (without making any changes to the data displayed), the "Password" is stored as null in database. I think this is because there is no data in the field displayed and this should not be the normal behaviour.

    3. Is it normal not to give option to change password in Edit Mode?

    Kindly reply

    Regards

    Venkatesh G

     

  • Re: How to set Displayformat for a password field?

    05-21-2009, 4:11 AM
    • Star
      12,112 point Star
    • sjnaughton
    • Member since 04-29-2008, 5:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,535
    • TrustedFriends-MVPs

    venkatesh.g2:

    2. If you click on update hyperlink from edit mode (without making any changes to the data displayed), the "Password" is stored as null in database. I think this is because there is no data in the field displayed and this should not be the normal behaviour.

    Duh! sorry I should have fixed that I'll update the article.

    venkatesh.g2:
    3. Is it normal not to give option to change password in Edit Mode?

    That depends on the situationif you wanted it read only you could have the Edit version being the same as the normal and the have what is currently the Edit as the insert i.e. Password_Insert.ascx.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: How to set Displayformat for a password field?

    05-21-2009, 5:01 AM
    Answer
    • Star
      12,112 point Star
    • sjnaughton
    • Member since 04-29-2008, 5:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,535
    • TrustedFriends-MVPs

    venkatesh.g2:

    2. If you click on update hyperlink from edit mode (without making any changes to the data displayed), the "Password" is stored as null in database. I think this is because there is no data in the field displayed and this should not be the normal behaviour.

    Fixed here Password FieldTemplates for Dynamic Data (UPDATED) just added a simple test to check if the TextBox.Text was not empty before returning it's value.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: How to set Displayformat for a password field?

    05-22-2009, 12:52 AM
    • Member
      1 point Member
    • venkatesh.g2
    • Member since 05-18-2009, 9:05 AM
    • Posts 7

    Thanks Steve,

    Its working fine now.

    Regards

    Venkatesh G

Page 1 of 1 (10 items)