ASP:文本框的值在回传时,只有密码消失 [英] ASP:TextBox Value disappears in postback only when password

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

问题描述

我有一个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试图发送密码值回客户端不允许你。如果你没事的安全问题(即它要么没有真正安全的信息或者你确保连接是安全的),你可以手动设置控制的属性,而不是它文本属性。它看起来是这样的:

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:文本框的值在回传时,只有密码消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆