asp:TextBox ReadOnly=true 或 Enabled=false?
asp:TextBox 控件的 Enabled 属性和 ReadOnly 属性之间有什么区别?
What's the difference between the Enabled and the ReadOnly-properties of an asp:TextBox control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果控件被
禁用
,则无法对其进行编辑并且在提交表单时其内容将被排除。如果控件是
只读
,则无法对其进行编辑,但其内容(如果有)仍包含在提交中。If a control is
disabled
it cannot be edited and its content is excluded when the form is submitted.If a control is
readonly
it cannot be edited, but its content (if any) is still included with the submission.另一种行为是,
readonly = 'true'
控件将触发click
等事件,但Enabled = False
控件则不会。Another behaviour is that
readonly = 'true'
controls will fire events likeclick
, butonEnabled = False
controls will not.Readonly 不会使文本框“灰显”,并且仍会在回发时提交值。
Readonly will not "grayout" the textbox and will still submit the value on a postback.
从浏览器的角度考虑一下。 对于只读,浏览器将发送变量/值对。 对于残疾人来说,不会。
运行它,然后在点击提交后查看 URL:
Think about it from the browser's point of view. For readonly the browser will send in a variable/value pair. For disabled, it won't.
Run this, then look at the URL after you hit submit:
只读将允许用户从中复制文本。 残疾人不会。
Readonly will allow the user to copy text from it. Disabled will not.
Asp.net 中的只读文本框
Readonly textbox in Asp.net
我有一个子 aspx 表单,它在服务器端执行地址查找。 然后,子 aspx 页面中的值通过 javascript 客户端传递回父文本框。
尽管您可以看到文本框已更改,但只读或启用都不允许将值回发到父表单中。
I have a child aspx form that does an address lookup server side. The values from the child aspx page are then passed back to the parent textboxes via javascript client side.
Although you can see the textboxes have been changed neither ReadOnly or Enabled would allow the values to be posted back in the parent form.