我正在嘗試啓用顯示/隱藏密碼功能。我正在使用C#創建一個asp.net web表單。嘗試在asp.net中啓用顯示/隱藏功能
我的代碼如下,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class show : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked == false)
{
TextBox1.TextMode = TextBoxMode.Password;
}
if (CheckBox1.Checked == true)
{
TextBox1.TextMode = TextBoxMode.SingleLine;
}
}
}
在mypage.aspx,
有一個複選框,其AutoPostBack屬性爲true,並且其文本框文本模式是密碼。
預期的結果是: -
顯示密碼輸入文本時複選框被選中。
未選中複選框時隱藏密碼。
的問題是: -
此代碼工作只有一次,即當複選框被選中或取消選中它再次沒有被執行。 該文本框變爲空白。
請儘快幫助我。
我建議不使用後這樣做了。當它主要應該是客戶端JavaScript時,這是一個非常繁重的方式。 –
感謝Kay Lee審查我的帖子。 –