Tuesday, February 3, 2009

ASP.NET 2.0 text field value is not being passed to code behind

Whenever ASP.NET 2.0 TextBox component is set to Disabled or ReadOnly through the VS2005 designer, and then modified by client JavaScript - input value is not being persisted on the postback.
To work around this - set Disabled or ReadOnly from the client JavaScript when the page loads.
e.g.

function ExecuteOnLoad()
{
document.getElementById("txtInput").readOnly = true;
document.getElementById("txtOutput").disabled = true;
}

1 comment:

myinfonexus said...

Another workaround is to simulate "readonly" behavior: http://codecorner.galanter.net/2009/10/09/postback-disabled-textbox/