的ReadOnly
属性设置为true 包括the attribute being set:
if (ReadOnly) {
writer.AddAttribute(HtmlTextWriterAttribute.ReadOnly, "readonly");
}
然而,属性也会影响到回发的行为。它只会保存在视图状态的文本时,它的not readonly(原代码缩短):
private bool SaveTextViewState {
get {
if (TextMode == TextBoxMode.Password) {
return false;
}
if (Events[EventTextChanged] != null || !IsEnabled || !Visible || (ReadOnly) || this.GetType() != typeof(TextBox)) {
return true;
}
return false;
}
}
而且控制也只尝试to restore it时是这样的话:
protected virtual bool LoadPostData(string postDataKey, NameValueCollection postCollection) {
// …
if (!ReadOnly && !current.Equals(postData, StringComparison.Ordinal)) {
Text = postData;
return true;
}
return false;
}