Home  >  Article  >  Backend Development  >  ASP.Net TextBox cannot obtain value through background assignment when it is read-only

ASP.Net TextBox cannot obtain value through background assignment when it is read-only

巴扎黑
巴扎黑Original
2016-12-19 17:16:051822browse

Today when I was developing an asp.net page, I encountered a situation where the ReadOnly attribute was set in the TextBox. After assigning a value in js, the background code could not get the value. After searching on the Internet, I found several solutions.
Collect it.
1. Do not set ReadOnly, set onfocus=this.blur()
C# code


The text box remains gray, but the content cannot be modified manually. You can pass it in the background The Text attribute is assigned and obtained normally
2. After setting the ReadOnly attribute, obtain the value through Request, as follows:
Front-end code:


Backend code:
string Text = Request.Form[" TextBox1"].Trim();
string Text = Request.Form["TextBox1"].Trim();
3. The read-only attribute of the text box is being set in Page_Load(), and it can be read normally, as follows:
C# Code
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TextBox1.Attributes.Add("readonly","true");
}
}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:c# .net serializes ListNext article:c# .net serializes List