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

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

MyCode.ControlMode = SPControlMode.Display

| improve this answer | |

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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