If a control is disabled
it cannot be edited and its content is excluded when the form is submitted.If a control is readonly
it cannot be edited, but its content (if any) is still included with the submission.
即: 当ReadOnly=True时,控件ID在前后天仍可以被查询到。而当Diabled=True, 或者当Visible=True时,一旦Form被前台递交,其ID将不再被前台识别;此时,TextBox空间和Label空间功能将相差无几。
实际代码中,由于Label控件的局限性,很多时候借用TextBox控件,但显示时何Label一样。如下代码
<asp:Textbox ID="lblComment" runat="server" Width="200" ReadOnly="true" Visible="True" BorderWidth="0px" BorderStyle="None" >
</asp:Textbox>
简单分析如下: 将 BorderWidth 设置为0,BorderStyle设置为None,其显示将和Label一样。Readonly设置为True,内部文字将不会被编辑。
下文增加一个js的控件属性修改function
function ShowComment(selectedcontrol, control1, control2, judgePara, width1, width2, msg) {
if (control1 != null && control2 != null) {
if (selectedcontrol.value == judgePara) {
control1.value = msg;
control2.style.width = width1;
}
else {
control1.value = "";
control2.style.width = width2;
}
}
}
其调用方法
<aspx:Textbox ID="txtCodeKubun" runat="server" ImeMode="Disabled" Width="30px" TabIndex="1"
onFocus="OnGreen('txtCodeKubun')"
onkeyup="TxtChange(this,document.getElementById('cmbCodeKubun'))"
onblur="TxtChangeBlur(this,document.getElementById('cmbCodeKubun'))"
onchange="ShowComment(this,document.getElementById('lblComment'),
document.getElementById('txtComment'),
'013','185px','400px','*Comment: how are you!')"
MaxLength="3" LengthAsBytes="true">
</aspx:Textbox>