微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何使文本框在asp.net中不可编辑(c#)

我正在创建一个ASP Web应用程序,在该应用程序中,一个表单必须更新文本框字段中的日期值,我将日历按钮放在该文本框附近.它可以更新该文本框字段中的日期但可编辑.我想通过仅使用日历按钮更新日期值,我使用只读属性但返回空值,因此不起作用.

解决方法

尝试客户端html readonly属性而不是ASP.NET服务器端readonly.

myTextBox.Attributes.Add("readonly","readonly");

来自MSDN,

The Text value of a TextBox control with the ReadOnly property set to true is sent to the server when a postback occurs,but the server does no processing for a read-only text Box. This prevents a malicIoUs user from changing a Text value that is read-only. The value of the Text property is preserved in the view state between postbacks unless modified by server-side code.

这就是为什么具有服务器端readonly属性的文本框在回发中具有空值.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐