Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a read-only textbox not return any data in ASP.NET?

Tags:

I've set a textbox to read-only. When the user clicks on it, a calendar is displayed and the user selects the date which inputs into the read-only textbox.

But when I try to enter the data into the database, it shows null value. What is wrong?

like image 687
input Avatar asked May 07 '09 10:05

input


2 Answers

There is a little bit of strangeness when it comes to the ASP.NET Readonly property and the readonly attribute of an HTML input element. Rather than setting the Readonly property of the web control try simply adding the HTML attribute to the control like this:

textBox.Attributes.Add("readonly", "readonly"); 

This will make the control read-only in the client's browser yet still allow you to retrieve the value of the input when it posts back to the server.

like image 161
Andrew Hare Avatar answered Sep 17 '22 16:09

Andrew Hare


The system assumes that read only or disabled controls won't be changed clientside so it doesn't post the changed value back to the server. You need to set the client side readonly property rather than the serverside version.

like image 27
Tom Clarkson Avatar answered Sep 18 '22 16:09

Tom Clarkson