Juri Strumpflohner
Juri Strumpflohner Juri is a full stack developer and tech lead with a special passion for the web and frontend development. He creates online videos for Egghead.io, writes articles on his blog and for tech magazines, speaks at conferences and holds training workshops. Juri is also a recognized Google Developer Expert in Web Technologies

Revised: Changed values of readonly and disabled fields....

1 min read

In a previous post I wrote about the problem that the values of readonly or disabled fields are not retrieved after a postback because it appears as if ASP.net doesn't handle their viewstate. I don't know whether this was a design choice because they assumed that readonly fields aren't supposed to change or whether it is a bug. Anyway, as I've stated, it may nevertheless be the case where the values of readonly fields are modified (i.e. by JavaScript).
In my previous post I've described a workaround that uses JavaScript to prevent any user-input etc...This may however not always be the best solution since you have for instance to handle the tab-key explicitly because otherwise it won't be possible to navigate over your text-field by pressing the tab-key (the cursor would get stuck on your textbox). So a better solutions is to leave the text-field as it is, adding the readonly property to "true" and doing whatever you need. You also don't need any JavaScript event handlers. What you have to do instead is to explicitly retrieve the value of your text-field in the PageLoad event by querying the Request object:
txbWorkOfficeCompanyCode.Text = Request[this.txbWorkOfficeCompanyCode.UniqueID];

Questions? Thoughts? Hit me up on Twitter
comments powered by Disqus