ASP:TextBox 值仅在密码时才会在回发中消失

ASP:TextBox Value disappears in postback only when password(ASP:TextBox 值仅在密码时才会在回发中消失)

本文介绍了ASP:TextBox 值仅在密码时才会在回发中消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的 asp.net 文本框:

I have an asp.net textbox like this:

 <asp:TextBox ID="PINPad" runat="server" Columns="6" MaxLength="4" 
      CssClass="PINTextClass"></asp:TextBox>

您可能已经猜到了,它是来自屏幕密码键盘的文本框.Javascript 填充值.该页面每五秒发布一次(如果重要,使用更新面板)以更新屏幕上的各种其他不相关项目.这工作得很好.

It is, as you might have guessed, the text box from an on screen PIN pad. Javascript fills in the values. The page is posted back every five seconds (using an update panel if that matters) to update various other unrelated items on the screen. This works just fine.

但是,当我将其转换为密码文本框时,如下所示:

However, when I convert it to a password text box, like this:

  <asp:TextBox ID="PINPad" runat="server" Columns="6" MaxLength="4" 
       CssClass="PINTextClass" TextMode="Password"></asp:TextBox>

然后,每当页面回发时,屏幕上的文本框就会被清除,文本框是空的(尽管在计时器事件期间,该值确实会返回到服务器.)

Then whenever the page posts back, the text box is cleared out on the screen and the textbox is empty (though during the timer event, the value does make it back to the server.)

有什么建议可以解决这个问题,以便在回发期间保持其价值?

Any suggestions how to fix this, so that it retains its value during postback?

推荐答案

作为一项安全功能,ASP.NET 会尝试禁止您将密码值发送回客户端.如果您对安全问题没有意见(即它不是真正安全的信息,或者您确定连接是安全的),您可以手动设置控件的 "value" 属性,而不是而不是使用它的 Text 属性.它可能看起来像这样:

As a security feature, ASP.NET tries to disallow you from sending the password value back to the client. If you're okay with the security issues (i.e. it's either not really secure information or you're sure that the connection is secure), you can manually set the "value" attribute of the control, rather than using its Text property. It might look something like this:

this.PINPad.Attributes.Add("value", this.PINPad.Text);

这篇关于ASP:TextBox 值仅在密码时才会在回发中消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:ASP:TextBox 值仅在密码时才会在回发中消失

基础教程推荐