1

How do I apply Both a Password and Masked Template in textbox? For example, This is a template, as user keeps typing, the numbers (9) will disappear and replaced with star * asterisks, as user types credit card number.

Ideal Goal:

enter image description here

Current code:

The Current View below, only shows stars * to begin with, and stars as user keeps typing.

enter image description here

TagBuilder:

namespace Web.UI.TagHelpers
{
    [HtmlTargetElement(HtmlTargetElementConts.MaskedTextBox)]
    public class MaskedTextBoxTagHelper : MaskedTextBoxTagHelper
    {
        [HtmlAttributeName("MaskText")]
        public string MaskText { get; set; }

        [HtmlAttributeName("ValueText")]
        public string ValueText { get; set; }

        [HtmlAttributeName("IsPassword")]
        public bool IsPassword { get; set; }

        public MaskedTextBoxTagHelper(IKendoHtmlGenerator generator) : base(generator)
        {
        }

        public override void Process(TagHelperContext context, TagHelperOutput output)
        {

            this.Mask = MaskText;
            this.Value = ValueText;

            if (IsPassword == true)
            {
                output.Attributes.SetAttribute("type", "password");
            }

            base.Process(context, output);
        }
    }
}

View:

<maskedtextbox name="creditcardtest"
                    MaskText="0000-0000-0000-0000"
                    ValueText="9999-9999-9999-9999"
                    IsPassword="true">               
</maskedtextbox>
jerrythomas38
  • 759
  • 2
  • 16
  • 41

0 Answers0