如何使文本框在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属性的文本框在回发中具有空值.

相关文章

### 创建一个gRPC服务项目(grpc服务端)和一个 webapi项目(...
一、SiganlR 使用的协议类型 1.websocket即时通讯协议 2.Ser...
.Net 6 WebApi 项目 在Linux系统上 打包成Docker镜像,发布为...
一、 PD简介PowerDesigner 是一个集所有现代建模技术于一身的...
一、存储过程 存储过程就像数据库中运行的方法(函数) 优点:...
一、Ueditor的下载 1、百度编辑器下载地址:http://ueditor....