我在网络表单上有几个按钮,当用户点击它们时,它们将更新文本框。这工作直到我添加了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;
}
我也厌倦了这个:
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;
}
你多么绝望?
如果你没有绝望的尝试任何东西,任何事情让它发挥作用,请不要继续阅读。这不会很好。好?好。
诀窍是让网络应用程序认为它不是密码框。换句话说,不要使用TextMode="password"
。
然后在Page_Load
,把txt_punch.Attributes["type"] = "password"
而已。浏览器将知道它是一个密码字段(并显示星号或点),但服务器端将不知道,因此它将内容发送到客户端,因为它是纯文本。当然,这也会将密码放在页面源代码中......
将TextBox的TextMode属性设置为Password时,默认行为是不显示Text属性的值。
这是为了防止在页面的HTML源中显示未屏蔽的密码。
一种解决方案是使用属性来保存密码值:
TextBox.Attributes.Add("value", "yourPassword");
根据Kola的答案选择你可以试试这个:
TextBox.Attributes["value"] = "Whatever value goes here";
这是一个asp.net BUG !!电子邮件验证算法非常严格,导致排除了一些有效的电子邮件。如果您从“密码”tp“SingleLine”切换TextMode,您的代码将起作用。
我们无法直接将值分配给密码文本框。为文本框密码赋值,我们应该使用文本框属性
Textbox1.Attributes.Add("value",variable/"string");
当您将文本框的属性设置为TextMode =“密码”时,在编辑模式下文本框显示为空白。如果你填写价值
TextBox.Text = "Password";
然后不工作,你需要再次输入密码来保存表格。您可以使用属性来填充文本框中的值,如下面的代码。
TextBox.Attributes["value"] = "your password value";
密码通常不是为了显示,但如果你打算这样做,这个页面可能会帮助你Solution