zl程序教程

您现在的位置是:首页 >  移动开发

当前栏目

asp.netTextBox控件设置ReadOnly后,不能回传。

ASP 设置 不能 控件 readonly 回传
2023-06-13 09:14:09 时间
很奇怪,以前都没有过这样的怪问题,在别人机器上都能正常,想到可能和ASP.NET的版本有关系。
我用的是ASP.NET2.0,当改成ASP.NET1.0,就正常了,TextBox控件ReadOnly=True,能回传。
在ASP.NET1.0中是ReadOnly=True会回传的。
在ASP.NET2.0中是ReadOnly=True就不会回传了。

解决的方法:
<asp:textboxid="Username"runat="server"ReadOnly="True"></asp:textbox>
去掉ReadOnly="True",改成
<asp:textboxid="Username"runat="server"></asp:textbox>

在后台代码中加入,控制只读属性
Username.Attributes.Add("Readonly","True");
这样在ASP.NET2.0中只读的TextBox控件也能实现回传。