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 ::..
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?
hi,
didn’t check it out, but maybe it helps if you use Page.IsPostback ?