控件不管是设置 Enabled="false" 还是ReadOnly="true",后台都取不到前台的值,值为“空”;

界面视觉上,Enabled="false" 与 ReadOnly="true" 的区别是一个自带背景色,一个没有背景色。这个是对于textbox而言是很明显的。对于DropdownList 有没有背景色就不是那么明显了。至于asp:label 的话,我是还没试过,所以不知道,哈哈哈……

<asp:TextBox ID="txt_MailType" runat="server"></asp:TextBox>
<asp:TextBox ID="txt_Remark" runat="server" Enabled="false"></asp:TextBox>
<asp:TextBox ID="txt_Remark" runat="server" ReadOnly="true" style="background-color:#999999;"></asp:TextBox>

即便你在浏览器控制台中用js给文本赋值,该值也传不到后台的

$("#txt_MailType").val("789")

在后台也可以添加属性

this.txt_Remark.Enable = false;
this.txt_MailType.ReadOnly = true;

也可以这样添加属性滴

this.txt_Remark.Attributes.Add("readonly","true");

然后,我注意了下,运行代码,在浏览器的元素查看器里:

Enabled="false"   相当于input:text 的 disable="disable"
ReadOnly="true"   相当于 input:text 的 readonly="readonly"

为啥会这样的,我目前也没深究……

posted on 2018-08-14 10:13  欲穷  阅读(306)  评论(0编辑  收藏  举报