在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
偶然在一个老外的blog里看到有这样的描述,当textbox控件里被设置为readonly时,而且页面的enableviewsate设置为false时,提交后,textbox的值会丢失,这只发生在asp.net 2.0中,在asp.net 1.0/1.1中不会出现这样的情况,代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { this.Textbox1.Text = "readonly text"; } } protected void Button1_Click(object sender, EventArgs e) { this.lblMessage.Text = this.Textbox1.Text; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <asp:textbox ID="Textbox1" runat="server" ReadOnly="true" ForeColor="silver"></asp:textbox> <asp:textbox ID="Textbox2" runat="server" ReadOnly="true">Some Text</asp:textbox> <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br /> <asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label> </form>
MSDN 2005的解析: The Text value of a TextBox control with the ReadOnly property set to true is sent to the server when a postback occurs, but the server does no processing for a read-only text box. This prevents a malicious user from changing a Text value that is read-only. The value of the Text property is preserved in the view state between postbacks unless modified by server-side code. |
请发表评论