Skip to content Skip to sidebar Skip to footer

How To Set Passwordchar Property To Asp.net Textbox?

I have one TextBox for Password and i want to set character for password, so which property can be used in asp.net?

Solution 1:

PasswordChar property is under this namespace, System.Windows.Forms. It is not available for asp .net web applications.

You could try JavaScript to change it into other characters such as "*" or "@".

You can see the following example to do so:

<scripttype="text/javascript">functiononTextChange(obj)
        {
            document.getElementById('hdnActualTextValue').value = obj.value;
            obj.value = '';
            for(int i=0; i<obj.value.length;i++)
            {
                obj.value +='*';//OR ANY OTHER CHARACTER OF YOUR CHOICE
            }
        }
        </script><asp:TextBoxID="txtValue"runat="server"onblur="javascript:onTextChange(this);"onkeyup="javascript:onTextChange(this);"onkeypress="javascript:onTextChange(this);"></asp:TextBox><asp:HiddenFieldID="hdnActualTextValue"runat="server" />

OR maybe you could use input in HTML.

<label>PW: <inputtype="password"></label>

Solution 2:

I think if you are using the Web Forms then in that the Password Characters are fixed. You can not change unless you use Javascript to change some behavior at run time

When we use WebForms in that PasswordCharacters are set by default.

Check out this link. You can get some Idea what I am telling you.

Solution 3:

Simply use TextMode property in asp

<asp:TextBoxID="txtValue"runat="server"TextMode ="Password"></asp:TextBox>

Post a Comment for "How To Set Passwordchar Property To Asp.net Textbox?"