ASP.NET 2.0中ReadOnly的TextBox
来源:互联网 发布:mac 电源 编辑:程序博客网 时间:2024/05/17 07:32
有时候,我们不希望用户直接编辑TextBox,而是希望通过客户端脚本的方式来设置内容,一般的做法是设置TextBox的属性ReadOnly为true。但在ASP.NET 2.0里有了变化,设置了ReadOnly为true的TextBox,在服务器端不能通过Text属性获取在客户端设置的新内容,在Reflector里比较一下LoadPostData的实现
.NET 1.1中,
bool IPostBackDataHandler.LoadPostData(string postDataKey, NameValueCollection postCollection)
{
string text1 = this.Text;
string text2 = postCollection[postDataKey];
if (!text1.Equals(text2))
{
this.Text = text2;
return true;
}
return false;
}
.NET 2.0中,
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
base.ValidateEvent(postDataKey);
string text1 = this.Text;
string text2 = postCollection[postDataKey];
if (!this.ReadOnly && !text1.Equals(text2, StringComparison.Ordinal))
{
this.Text = text2;
return true;
}
return false;
}
就可以看出,如果设置了ReadOnly为true,从客户端传回的新的值是不被设置到Text属性的。
想要保持.NET 1.*中的行为,建议的做法是设置客户端属性ContentEditable=false,参考
SYSK 118: ReadOnly or ContentEditable?
http://blogs.msdn.com/irenak/archive/2006/05/03/589085.aspx
其实如果是设置客户端属性的话,设置客户端的readonly属性应该也是可以的:
TextBox1.Attributes["readonly"] = "true";
- ASP.NET 2.0中ReadOnly的TextBox
- ASP.NET 2.0中ReadOnly的TextBox
- ASP.NET 2.0中ReadOnly的TextBox
- ASP.NET 2.0 中TextBox的ReadOnly属性问题
- asp.net textbox readonly
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET 2.0中TextBox服务器控件的ReadOnly和Disabled属性
- ASP.NET 中TextBox设置ReadOnly或者Disable后获取不到值的解决办法
- ASP.NET 中TextBox设置ReadOnly="true" 无法取到值的做法
- ASP.NET 中TextBox设置ReadOnly="true" 无法取到值的做法
- ASP.NET 中TextBox设置ReadOnly="true" 无法取到值的做法(转)
- ASP.NET 中TextBox设置ReadOnly="true" 无法取到值的做法
- asp.net textbox的readonly属性设置方案
- 使用 SMS 编程的应用程序介绍
- 使用 .NET 和后台智能传输服务 API 来编写自动更新应用程序
- 关于cpu cache管理
- SONY WM-DD9开膛图片
- 使用 Windows Mobile 5.0 中的图片、视频和照相机
- ASP.NET 2.0中ReadOnly的TextBox
- 邂逅阎应元
- 2008-4-7 Struts 2概述(二)
- InetAddress与String类型的转换,byte[]型与String型转换,编码解码
- 买了个笔记本USB2.0卡却用不了
- 代码解决Oracle in列表过长问题
- J2ee学习流程
- CPU 的 cache 和 latency_立华软件园_游戏开发->程序设计->优化调试
- WinCE中基于Media Player的多媒体开发