I have one TextBox for Password and i want to set character for password, so which property can be used in asp.net?
<asp:TextBox TextMode="Password" runat="server" />
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 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:
<script type="text/javascript">
function onTextChange(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:TextBox ID="txtValue" runat="server" onblur="javascript:onTextChange(this);"
onkeyup="javascript:onTextChange(this);" onkeypress="javascript:onTextChange(this);"></asp:TextBox>
<asp:HiddenField ID="hdnActualTextValue" runat="server" />
OR maybe you could use input in HTML.
<label>PW: <input type="password"></label>
Method 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.
Method 3
Simply use TextMode property in asp
<asp:TextBox ID="txtValue" runat="server" TextMode ="Password"> </asp:TextBox>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0