While most of us are busy sleeping on Sunday mornings, I'm out having coffee with fellow developer's chatting about .NET stuff. The GTANetPro group get together once a week (Sunday @10AM). Each of us give an informal presentation on .NET technologies. It's a great way to tune up your presentation skills without the pressures of a formal atmosphere.
Last week Dave (SangYun Lee) gave a presentation on read only text boxes and how the value is not post back in ASP.NET 3.5. The same is true for ASP.NET 2.0. In 1.1 the value was post back correctly. Thanks to Dave for a great presentation.
Let me explain further. Figure 1 shows the behaviour of a read only text box with it's read only state is set declaratively with the ReadOnly attribute. When the user selects the button labelled Set Text with No Postback, the setText javascript function is called and sets the text to good day. Afterwards the users selects the Do Postback button and the text returns to it's previous state, that is, ReadOnly. The text is correctly posted back but the asp.net runtime is not setting the Text to good day. This was not the behaviour in ASP.NET 1.1. Is this a bug? I believe so! However, it looks like going forward this will be the behaviour.
Figure 1:
So what do we do?
The next figure has similar code except this time the read only attribute is not set declaratively, but, rather, it is set in the code behind during the loading of the page. Again when the user selects the Set Text with No Postback button the text in the text box is set to good day. However, this time when the Do Postback button is selected the text after the post back is remains set to good day.
I consider this a work around and until Microsoft changes this behaviour you will need to set the read only attribute programmatically using the Attributes.Add method. Given that this behaviour exists in ASP.NET 2.0 and 3.5 it looks like we may be stuck with this for a while.
Figure 2:
Thanks again Dave for a great presentation!
Guess the movie
The path of the righteous man is beset on all sides by the iniquities of the selfish and the tyranny of evil men. Blessed is he, who in the name of charity and good will, shepherds the weak through the valley of darkness, for he is truly his brother's keeper and the finder of lost children. And I will strike down upon thee with great vengeance and furious anger those who would attempt to poison and destroy my brothers. And you will know my name is the Lord when I lay my vengeance upon thee.