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

巴扎黑
Release: 2016-12-19 17:16:05
Original
1764 people have browsed it

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");
}
}

Related labels:
c#
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!