When ReadOnly = "True" is set for TextBox on the page, values cannot be assigned to the background code. The following methods can be avoided:
1. If ReadOnly is not set, set onfocus = this. blur ()
C # code
- <Asp: TextBox ID = "TextBox1" runat = "server" onfocus = this. blur ()> </asp: TextBox>
The Text box remains gray, but the content cannot be manually modified. You can assign values through the Text attribute in the background.
2. After the ReadOnly attribute is set, use the Request parameter as follows:
Front-end code:
C # code
- <Asp: TextBox ID = "TextBox1" runat = "server" ReadOnly = "True"> </asp: TextBox>
Background code:
C # code
- String Text = Request. Form ["TextBox1"]. Trim ();
3. Set the read-only attribute of the text box in Page_Load () to read normally, as shown below:
C # code
- Protected void Page_Load (object sender, EventArgs e)
- {
- If (! Page. IsPostBack)
- {
- TextBox1.Attributes. Add ("readonly", "true ");
- }
- }
-