Disabled TextBox content not PostBack to Server in ASP.NET 2.0

You are having a web page with text box and button. When you click on Button, the value content by TextBox is posted to server.

Now suppose one scenario is such that you already have got value of text box content while showing the web page. You don’t wish user to change this value.

So you have to disable TextBox, so that value can not be entered. TextBox can be disabled by code in JavaScript:-

document.getElementById("textBox1").disabled="disabled";

The disabled TextBox in JavaScript can be eanble by

document.getElementById("textBox1").disabled=false;

But the problem is that ASP.NET 2.0 do not recognize value supplied in TextBox if it is disabled. This is the way they have changed ASP.NET structure from 1.1 To 2.0.

The solution to this that I have found for this problem is enable property of Form to submit Disabled Controls.

This can be achieved by this line in PageLoad

Page.Form.SubmitDisabledControls = true;

Happy Coding!!

Popular posts from this blog

Weekend Gateway Trip - Shrivardhan

Cross Apply Incorrect syntax near '.'

Apply CSS Class based on Browser