通过Javascirpt设置TextBox的Text,设置完成后Text显示正常。

问题:
将TextBox的Enabled设置为False时 通过Javascirpt设置该TextBox的Text,设置完成后Text显示正常。 但是后台取不到值。 之前,设置ReadOnly为True时取不到,设置Enabled为False时没问题,现在设置Enabled为False也取不到值了。
解决方法:
这是ASP.NET为了安全性考虑,在服务器端不处理只读文本框
1.可以在后台绑定readonly=true
protected void Page_Load(object sender, EventArgs e) { TextBox1.Attributes.Add("readonly", "true"); }
2.通过焦点来控制
="this.blur();" _disibledevent=>="return false" _disibledevent=>="return false">
3.通过css来控制
.TextBoxReadOnly { border:1px solid #C0C0C0; text-align:left; background-color:#D3D3D3; width:100px; readonly:expression(this.readOnly=true); }
4.使用input加runat="server"代替
5.使用Attribute["readonly"]="readonly"或者Attribute.Add("readonly","readonly")而不是直接使用ReadOnly=true
Tags: 

延伸阅读

最新评论

发表评论