다음을 통해 공유


Custom Field Control not allowing more than 255 characters

Have you faced the issue of getting limited to 255 characters when working with your custom field controls? Especially, when you are inheriting from a field such as SPFieldMultiColumn! When you save an item having custom field control with more than 255 characters, you can get this type of message:


Invalid text value
A text field contains invalid data. Please check the value and try again.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Runtime.InteropServices.COMException: Invalid text value
A text field contains invalid data. Please check the value and try again.
Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


It's really disturbing that you chose MultiColumn field control because you wanted to store multiple values and the combined length of values in all the columns cannot exceed 255 characters!

The issue is generally that you have not chosen correct "ParentType" in fldtypes.xml file. In many samples available on internet, the "ParentType" is generally "Text", which is designed only for 255 characters. So even when in your code, you have inherited from a class other than SPFieldText e.g. SPFieldMultiColumn, the basic properties are governed by what ParentType you have chosen in the xml file. For example, for SPFieldMultiColumn this value should be as given below:

<Field Name="ParentType">MultiColumn</Field>

Generally, what value you should choose in ParentType can be referred from this page in SDK: Field Element (List - Definition) Interestingly, the above URL mentions ParentType for SPFieldMultiColumn as "Note". Both works as MultiColumn also rolls up to "Note" which is Parent Type for many field controls.

Comments