加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 03:39:24 所属栏目:asp.Net 来源:网络整理
导读:我正在创建一个ASP Web应用程序,在该应用程序中,一个表单必须更新文本框字段中的日期值,我将日历按钮放在该文本框附近.它可以更新该文本框字段中的日期但可编辑.我想通过仅使用日历按钮更新日期值,我使用只读属性但返回空值,因此不起作用. 解决方法 尝试客户
我正在创建一个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属性的文本框在回发中具有空值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读