文本框使用textmode密码不显示文本asp.net c#

时间:2021-09-09 04:22:37

I have a few buttons on a web form, and when the user clicks them they will update the the textbox. This worked till I added the textmode = password. Now the textbox doesn't show the text anymore. I debugged the app, and the text property is getting the value, but once again it is not showing.

我在网络表单上有几个按钮,当用户点击它们时,它们将更新文本框。这工作直到我添加了textmode =密码。现在文本框不再显示文本。我调试了应用程序,文本属性正在获取值,但再次没有显示。

Here is what I have tried:

这是我尝试过的:

 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;

    }

I have also tired this:

我也厌倦了这个:

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;

    }

6 个解决方案

#1


50  

How desperate are you?

你多么绝望?

If you're not desperate enough to try anything, anything to get it to work, don't read on. This will not be nice. OK? OK.

如果你没有绝望的尝试任何东西,任何事情让它发挥作用,请不要继续阅读。这不会很好。好?好。

The trick is to make the web app think that it's not a password box. In other words, don't use TextMode="password".
Then in Page_Load, put txt_punch.Attributes["type"] = "password"

诀窍是让Web应用程序认为它不是密码框。换句话说,不要使用TextMode =“password”。然后在Page_Load中,输入txt_punch.Attributes [“type”] =“password”

That's it. The browser will know it's a password field (and show asterisks or dots), but the server side won't know, so it will send the content to the client as it it were plain text. Of course, this will also put the password in the page source...

而已。浏览器将知道它是一个密码字段(并显示星号或点),但服务器端将不知道,因此它将内容发送到客户端,因为它是纯文本。当然,这也会把密码放在页面源代码中......

#2


14  

When you set the TextMode property of a TextBox to Password the default behaviour is for it not to display the value of the Text property.

将TextBox的TextMode属性设置为Password时,默认行为是不显示Text属性的值。

This is to prevent unmasked passwords being shown in the HTML source of the page.

这是为了防止在页面的HTML源代码中显示未屏蔽的密码。

One solution is to use an attribute to hold the password value:

一种解决方案是使用属性来保存密码值:

TextBox.Attributes.Add("value", "yourPassword");

Source

资源

#3


0  

Based off option one of Kola's answer you can try this:

根据Kola的答案选择你可以试试这个:

TextBox.Attributes["value"] = "Whatever value goes here";

#4


0  

This is an asp.net BUG!! The email validation algorithm is very strict, resulting in the exclusion of some valid emails. If you switch the TextMode from "Password" tp "SingleLine", your code will work.

这是一个asp.net BUG !!电子邮件验证算法非常严格,导致排除了一些有效的电子邮件。如果您从“密码”tp“SingleLine”切换TextMode,您的代码将起作用。

#5


0  

we cant directly assign values to password text box. for assign values to text box password we should use textbox attributes

我们无法直接将值分配给密码文本框。为文本框密码赋值,我们应该使用文本框属性

Textbox1.Attributes.Add("value",variable/"string");

#6


-1  

Password generally are not meant to SHOW, but if you are intended to do so this page may help you Solution

密码通常不打算显示,但如果您打算这样做,此页面可能会帮助您解决问题

#1


50  

How desperate are you?

你多么绝望?

If you're not desperate enough to try anything, anything to get it to work, don't read on. This will not be nice. OK? OK.

如果你没有绝望的尝试任何东西,任何事情让它发挥作用,请不要继续阅读。这不会很好。好?好。

The trick is to make the web app think that it's not a password box. In other words, don't use TextMode="password".
Then in Page_Load, put txt_punch.Attributes["type"] = "password"

诀窍是让Web应用程序认为它不是密码框。换句话说,不要使用TextMode =“password”。然后在Page_Load中,输入txt_punch.Attributes [“type”] =“password”

That's it. The browser will know it's a password field (and show asterisks or dots), but the server side won't know, so it will send the content to the client as it it were plain text. Of course, this will also put the password in the page source...

而已。浏览器将知道它是一个密码字段(并显示星号或点),但服务器端将不知道,因此它将内容发送到客户端,因为它是纯文本。当然,这也会把密码放在页面源代码中......

#2


14  

When you set the TextMode property of a TextBox to Password the default behaviour is for it not to display the value of the Text property.

将TextBox的TextMode属性设置为Password时,默认行为是不显示Text属性的值。

This is to prevent unmasked passwords being shown in the HTML source of the page.

这是为了防止在页面的HTML源代码中显示未屏蔽的密码。

One solution is to use an attribute to hold the password value:

一种解决方案是使用属性来保存密码值:

TextBox.Attributes.Add("value", "yourPassword");

Source

资源

#3


0  

Based off option one of Kola's answer you can try this:

根据Kola的答案选择你可以试试这个:

TextBox.Attributes["value"] = "Whatever value goes here";

#4


0  

This is an asp.net BUG!! The email validation algorithm is very strict, resulting in the exclusion of some valid emails. If you switch the TextMode from "Password" tp "SingleLine", your code will work.

这是一个asp.net BUG !!电子邮件验证算法非常严格,导致排除了一些有效的电子邮件。如果您从“密码”tp“SingleLine”切换TextMode,您的代码将起作用。

#5


0  

we cant directly assign values to password text box. for assign values to text box password we should use textbox attributes

我们无法直接将值分配给密码文本框。为文本框密码赋值,我们应该使用文本框属性

Textbox1.Attributes.Add("value",variable/"string");

#6


-1  

Password generally are not meant to SHOW, but if you are intended to do so this page may help you Solution

密码通常不打算显示,但如果您打算这样做,此页面可能会帮助您解决问题