Showing posts with label Even Handlers. Show all posts
Showing posts with label Even Handlers. Show all posts

Tuesday, October 14, 2014

Get List item values in ItemAdding event handler

In an Item Adding event handler Properties.ListItem will be null. Same is the case with Properties.BeforeProperties & Properties.AfterProperties too. So how to get the values entered in the NewForm.aspx in the ItemAdding method. Here we go..
You can access the value using AfterProperties property. But here you have to pass the internal name of the column whose value you want to access.
properties.AfterProperties["Internal Name of the column"]
Or in case if you don’t know/want to explicitly specify the internal name you can get the same using Field.InternalName property. The below code snippet I used explains the same.
string employeeInternalName = Convert.ToString(site.Lists[properties.ListId].Fields["EmployeeName"].InternalName);
string employeeName= Convert.ToString(properties.AfterProperties[employeeInternalName]);