我正在尝试在我的文本框 - 密码下面创建一个“显示密码”复选框,以取消屏蔽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没有,我试图重启视觉工作室和我的笔记本电脑,希望它只是一个错误,但仍然无法工作..我想知道我的编码是否错误。
如果条件都是如此,结果将如何不同
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;
}