SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm developing a user control containing textfields bound to my list SPListFields and I'm using this user control twice with two different modes ( Edit or New).

In my Edit mode I want to disable a TextField wich is bound to the SPListItem Code but I didn't now how to do it from code behind ??

Here's the TextField Code :

TextField MyCode = new TextField();
MyCode.ID = "MyCodeID";
MyCode.FieldName = "Code";
MyCode.ItemId = myItemID;
MyCode.ListId = myListID;
MyCode.ControlMode = Mode == OperationMode.Edit ? SPControlMode.Edit : SPControlMode.New;
if (Mode == OperationMode.Edit)
    MyCode.enabledViewState = false // this doesn't enable my textField
share|improve this question
up vote 2 down vote accepted

If you want the field to appear as read-only or display than you can change its SPControlMode to Display

MyCode.ControlMode = SPControlMode.Display

share|improve this answer

enabledViewState wouldn't enable/disable your field, try .Enabled instead.

share|improve this answer
that option doesn't exist – Glolita Mar 25 '13 at 10:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.