An ASP cannot be assigned to a value by a background when it is read-only
Source: Internet
Author: User
Today in the development of an ASP. NET page encountered a TextBox set the ReadOnly property, after the assignment in JS, the background code does not take the value of the case, after searching on the internet, found a few ways to deal with.
Collect them.
1, do not set ReadOnly, set Onfocus=this.blur ()
C # code
<asp:textbox id= "TextBox1" runat= "Server" Onfocus=this.blur () ></asp:TextBox>
<asp:textbox id= "TextBox1" runat= "Server" Onfocus=this.blur () ></asp:TextBox>
The text box is not dimmed, but you cannot modify the content manually, and you can use the Text property to assign values in the background
2. After setting the ReadOnly property, the value is obtained by request, as follows:
Front Code:
<asp:textbox id= "TextBox1" runat= "Server" readonly= "True" ></asp:TextBox>
<asp:textbox id= "TextBox1" runat= "Server" readonly= "True" ></asp:TextBox>
Background code:
String Text = request.form["TextBox1"]. Trim ();
String Text = request.form["TextBox1"]. Trim ();
3, in Page_Load () is setting the text box read-only properties, can read normally, as follows:
C # code
protected void Page_Load (object sender, EventArgs e)
{
if (! Page.IsPostBack)
{
TEXTBOX1.ATTRIBUTES.ADD ("ReadOnly", "true");
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.