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:



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;
}


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.

Karsten Pohnke About Karsten Pohnke
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.

2 comments on “SharePoint 2013 Access other fields from your custom fieldtype II

  1. Kyle Daley

    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?

Submit comment

Allowed HTML tags: <a href="http://google.com">google</a> <strong>bold</strong> <em>emphasized</em> <code>code</code> <blockquote>
quote
</blockquote>

Please fill in the captcha: * Time limit is exhausted. Please reload CAPTCHA.