25

Web フォームにいくつかのボタンがあり、ユーザーがそれらをクリックすると、テキスト ボックスが更新されます。これは、 textmode = password を追加するまで機能しました。これで、テキスト ボックスにテキストが表示されなくなりました。アプリをデバッグし、テキスト プロパティが値を取得していますが、もう一度表示されません。

これが私が試したことです:

 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;

    }
4

7 に答える 7

61

あなたはどれほど絶望的ですか?

何かをしようとするほど絶望的でない場合、それを機能させるために何かをする必要がある場合は、読み進めないでください。これは良くありません。わかった?わかった。

秘訣は、Web アプリにパスワード ボックスではないと思わせることです。つまり、使用しないでくださいTextMode="password"
次にPage_Load、入れますtxt_punch.Attributes["type"] = "password"

それでおしまい。ブラウザーはそれがパスワード フィールドであることを認識します (そしてアスタリスクまたはドットを表示します) が、サーバー側は認識しないため、コンテンツはプレーン テキストとしてクライアントに送信されます。もちろん、これはページソースにもパスワードを入れます...

于 2013-05-24T18:51:36.663 に答える
15

TextBox の TextMode プロパティを Password に設定すると、デフォルトの動作では Text プロパティの値が表示されません。

これは、マスクされていないパスワードがページの HTML ソースに表示されるのを防ぐためです。

1 つの解決策は、属性を使用してパスワード値を保持することです。

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

ソース

于 2013-05-24T16:23:59.320 に答える
1

Kolaの回答のオプション1に基づいて、これを試すことができます:

TextBox.Attributes["value"] = "Whatever value goes here";
于 2016-05-30T13:47:23.577 に答える
-1

パスワードは通常、表示することを意図していませんが、表示することを意図している場合は、このページが役立つ場合があります

于 2013-05-24T16:42:39.037 に答える