In. in NET2.0, when the ReadOnly = "True" attribute is set for a TextBox on the page, assign a value to it through the client script, this value cannot be obtained when you access the Text attribute in the background code. After trying, we found that the problem can be solved in the following ways:
1. Do not set the ReadOnly attribute. Use onfocus = this. blur () to simulate
<Asp: TextBox ID = "TextBox1" runat = "server" onfocus = this. blur ()> </asp: TextBox>
In this case, the Text box is immediately lost when it gets the focus, so it cannot be manually modified, it can simulate ReadOnly, and the Text attribute can also be used in the background code, normally obtain the value set by the script on the client;
2. After the ReadOnly attribute is set, use the Request parameter to set the value.
Front-end code:
<Asp: TextBox ID = "TextBox1" runat = "server" ReadOnly = "True"> </asp: TextBox>
Background code:
String Text = Request. Form ["TextBox1"]. Trim ();
It is worth noting that:
We know that html is based on the control name, and the value in J2EE is like this. If nested, such as the master page and the Gridview. Then we must first obtain the uniqueID.
String uid = this.txt Birth. UniqueID;
String value = Request. Form [uid]. Trim ();
See ID, ClientID, UniqueID difference, read this article: http://www.bkjia.com/kf/201202/119612.html
3. the read-only attribute of the text box is set in Page_Load (), and can be read normally.
Protected void Page_Load (object sender, EventArgs e)
{
If (! Page. IsPostBack)
{
TextBox1.Attributes. Add ("readonly", "true ");
}
}
From Xu Yue's column