我正在创建一个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属性的文本框在回发中具有空值.