iandevlin.com

Icon

A mixture of musings on web design & development, history, and life

asp:Textbox – the difference between ReadOnly and Disabled

Again this may be something that is old news to some of you, and perhaps it is to me as well and I had forgotten, but today I was hugely frustrated with .NET seemingly ignoring some perfectly populated fields and the validators reporting that they were empty.

The fields in question had been populated with values from the database after a choice was made from a combobox and a quick AJAX call. When trying to submit, as mentioned, the specified field’s validators were complaining that they were missing. Which, as it turned out, to all intents and purposes, they were.

Why?

Well when I a choice was made from the combobox, I was setting the fields-to-populate to disabled, so they would be greyed out and the user would be unable to alter them. But this causes the browser to not post their values when submitting the form. Setting the ‘readonly’ attribute rather than the ‘disabled’ one effectively has the same effect except the values get posted when the form is submitted.

So remember folks:

document.getElementById('identifier').readOnly = true;

is the way to get over this.

http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/digg_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/reddit_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/stumbleupon_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/delicious_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/technorati_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/google_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/facebook_24.png http://www.iandevlin.com/blog/wp-content/plugins/sociofluid/images/twitter_24.png

No related posts.

Category: web development

Tagged: , ,

Leave a Reply

Fáilte

Welcome to the the blog of Ian Devlin, a web developer based in Cambridge in the UK. Here you'll find random posts on my main interests, web design/development, history and generally anything I feel like writing about.

Twitter Feed