.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";