我正在尝试在我的文本框下方制作一个"显示密码"复选框 - 密码 以取消屏蔽 txtpassword 并显示字符。
protected void chkUnmask_CheckedChanged(object sender, EventArgs e)
{
if (chkUnmask.Checked == true)
{
txtPassword.TextMode = TextBoxMode.Password;
}
else
{
txtPassword.TextMode = TextBoxMode.Password;
}
}
每次复选框更改为选中和未选中时,我都使用 If-Else 条件更改文本框的行为。它在WindowsFormApp C#中工作正常,但在WebApp C#中 ASP.net 则不能,我试图重新启动Visual Studio和我的笔记本电脑,希望这只是一个错误,但仍然不起作用。我想知道我的编码是否错误。
如果条件是
txtPassword.TextMode = TextBoxMode.Password;
}
You need to change the TextBox mode for one of the conditions
// I think you need to set break points and check if this line is being triggered
TextBox1.TextMode = TextBoxMode.SingleLine;
// you can try this code which works fine. Add a button, and a textbox and set its textmode to Password. Type something the then click the button.
protected void Button1_Click1(object sender, EventArgs e)
{
TextBox1.TextMode = TextBoxMode.SingleLine;
}