nat*_*ate 20 asp.net text textbox passwordbox c#-4.0
我在网络表单上有几个按钮,当用户点击它们时,它们将更新文本框.这工作直到我添加了textmode =密码.现在,文本框不再显示文本.我调试了应用程序,文本属性正在获取值,但它再次没有显示.
这是我尝试过的:
protected void btn_punch_7_Click(object sender, EventArgs e)
{
const string string_punch_Number_7 = "7";
var text = txt_punch.Text;
text += string_punch_Number_7;
txt_punch.Text = text;
}
protected void btn_punch_8_Click(object sender, EventArgs e)
{
const string string_punch_Number_8 = "8";
var text = txt_punch.Text;
text += string_punch_Number_8;
txt_punch.Text = text;
}
Run Code Online (Sandbox Code Playgroud)
我也厌倦了这个:
public partial class WebForm3 : System.Web.UI.Page
{
public string string_punch;
protected void Page_Load(object sender, EventArgs e)
{
MultiView1.SetActiveView(View1);
txt_punch.Width = 300;
txt_punch.Height = 50;
txt_punch.MaxLength = 4;
txt_punch.Attributes.Add("OnChange", string_punch);
}
protected void btn_punch_7_Click(object sender, EventArgs e)
{
const string string_punch_Number_7 = "7";
string_punch = txt_punch.Text;
string_punch += string_punch_Number_7;
txt_punch.Text = string_punch;
}
protected void btn_punch_8_Click(object sender, EventArgs e)
{
const string string_punch_Number_8 = "8";
string_punch = txt_punch.Text;
string_punch += string_punch_Number_8;
txt_punch.Text = string_punch;
}
Run Code Online (Sandbox Code Playgroud)
Mr *_*ter 56
你多么绝望?
如果你没有绝望的尝试任何东西,任何事情让它发挥作用,请不要继续阅读.这不会很好.好?好.
诀窍是让网络应用程序认为它不是密码框.换句话说,不要使用TextMode="password".
然后Page_Load,放入txt_punch.Attributes["type"] = "password"
而已.浏览器将知道它是一个密码字段(并显示星号或点),但服务器端将不知道,因此它将内容发送到客户端,因为它是纯文本.当然,这也会将密码放在页面源代码中......
Chr*_*isF 15
将TextBox的TextMode属性设置为Password时,默认行为是不显示Text属性的值.
这是为了防止在页面的HTML源中显示未屏蔽的密码.
一种解决方案是使用属性来保存密码值:
TextBox.Attributes.Add("value", "yourPassword");
Run Code Online (Sandbox Code Playgroud)