SharePoint 2013 Access other fields from your custom fieldtype II

I already posted about this topic in this article. With SharePoint 2013 the solution from the old post didn’t work for me, so i had to find another approach. And for my hapiness, i found a solution which i would like to present to you. The idea is -again- to access the other fields in a display, edit or new form of a list. So if something occurs the values of the column X like title can be changed. The question is how to access these fields which are also in the form?

Look at the code below:

[sourcecode language=”csharp”]

txtTitle = (TextField)GetFieldControlByName(“Feldname”);
txtTitle.ItemFieldValue = “Test”;
txtTitle.UpdateFieldValueInItem();

//Function to interact with other fields
protected BaseFieldControl GetFieldControlByName(String fieldNameToSearch)
{
if (this.Fields.ContainsField(fieldNameToSearch))
{
return this.Fields[fieldNameToSearch].FieldRenderingControl;
}
else
return null;
}

[/sourcecode]

At first i create a TextBox and call the function to get the textfield of the other column. So i call this.Fields.ContainsField(“Name”) in order to check if the field is available. If yes, i catch the FieldRenderingControl and return this one. After that i can cast it to Textfield.

To update or save the item just call your textbox with the function UpdateFieldValueInItem(). That’s it. Hope it helps you.

..:: I LIKE SHAREPOINT ::..

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. In his free time he tries to collect tipps and worthy experience in this blog.

2 Comments

  1. This appears to work great for initial load, but what about postback? For example, in the UI of creating a list item, I set the value of the datetime control to “2009-05-10”. When I get to the postback of MY field control, the value for that datetime control is DateTime.Now. Any ideas?

Leave a Reply

Your email address will not be published.


*