Welcome to AspAdvice Sign in | Join | Help

TextBox ReadOnly in ASP.NET v2.0

If TextBox's ReadOnly property is "true", postback data won't be loaded e.g it essentially means TextBox being readonly from server-side standpoint (client-side changes will be ignored). If you want TB to be readonly in the "old manner" use TextBox1.Attributes.Add("readonly","readonly") as that won't affect server-side functionality.

This is documented here:
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.readonly.aspx

And someone pointed that out as bug a while ago:
http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=60bb1325-9dc3-48e9-a32f-e211ea345862

Even though it's not even about EnableViewState but only about server-side ReadOnly property affecting postback data loading...

Published Wednesday, April 12, 2006 11:00 PM by joteke
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: TextBox ReadOnly in ASP.NET v2.0

Thank you very much for the "readonly" tip. I had the viewstate problem with my new datepicker control but now it works because of your useful tip.

I wonder ho come it has been designed like that, that viewstate is not saved on disabled textboxes, or maybe it has just slipped through Bill's fingers =D. Thanks anyway.

Sunday, May 07, 2006 6:37 AM by Atte Gartman

# re: TextBox ReadOnly in ASP.NET v2.0

Thank a lot! for the read only tip.
It helped me resolve the problem.
I tried reading the Viewstate using tools and every time after postback, the value is initialized.
Wednesday, July 12, 2006 2:29 PM by Puja

# re: TextBox ReadOnly in ASP.NET v2.0

Thanx dude, this code is great it has saved a lot of time of mine.Thanx again buddy.It worked great in 2.0.
Friday, July 21, 2006 3:38 AM by Arun

# Read only and TextBox...

Read only and TextBox...

Thursday, August 07, 2008 10:01 AM by Chem On The Web

# re: TextBox ReadOnly in ASP.NET v2.0

Thank you Joteke! Fantastic tip
Tuesday, November 04, 2008 5:02 PM by Jezza

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks, it help me a lot
Saturday, December 06, 2008 4:08 AM by Vinod chakote

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks. it's great!
Tuesday, December 23, 2008 11:27 PM by babe

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks. It's great!
Tuesday, December 23, 2008 11:32 PM by babe

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks a lot. Wonderful solution. This helps to solve a bib big problem. Cheers !!! Shahaji Udar
Tuesday, December 30, 2008 10:00 AM by Shahaji Udar

# re: TextBox ReadOnly in ASP.NET v2.0

Perfect solution. I had a read-only textbox that needed to be controlled by the client, but backdriven by the server. This solution was the key.
Saturday, January 10, 2009 11:30 AM by Robert N

# re: TextBox ReadOnly in ASP.NET v2.0

This is quite cool...thanks!
Wednesday, January 21, 2009 11:44 AM by He-man!

# re: TextBox ReadOnly in ASP.NET v2.0

Thank you, cool tip
Thursday, March 12, 2009 8:42 AM by eGm

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks it works
Wednesday, July 08, 2009 7:30 AM by vikas Kumar

# re: TextBox ReadOnly in ASP.NET v2.0

u rock dude!
Friday, July 17, 2009 4:04 AM by Som

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks for the code! very useful!
Sunday, July 26, 2009 11:39 PM by Luigi

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks a lot for the useful tip... It saved a lot of time for me...
Tuesday, August 04, 2009 10:44 AM by Subhash

# re: TextBox ReadOnly in ASP.NET v2.0

You rock man..!!!
Saturday, August 08, 2009 5:09 AM by Bal

# re: TextBox ReadOnly in ASP.NET v2.0

thanx Dude:)
Sunday, October 25, 2009 3:54 AM by Wael

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks... I hope someone was fired for that design
Tuesday, October 27, 2009 4:49 PM by Julián

# re: TextBox ReadOnly in ASP.NET v2.0

Excellent. This is what I was exactly looking for. Thank you.
Thursday, November 12, 2009 12:08 PM by Prem

# re: TextBox ReadOnly in ASP.NET v2.0

Thanks for infomation
Thursday, January 07, 2010 10:36 PM by Lew

# Readonly textbox not adding values to viewsate « Chris Gaskell’s Blog

Leave a Comment

(required) 
required 
(required) 
Enter the code you see below