I tried creating a custom frield type using the articles "Creating a Custom Field Type for SharePoint 2010 (Email Validation Field)" and MSDN article "Creating Custom SharePoint 2010 Field Types". In both cases I dont see any build /deployment errors. But still I dont see the custom field type in the list of options when I try to create a new column. Do I need to do anything on the Central Adinistration to make this work. Please help me with this.
0
votes
Sorry to ask, but has the feature been activated in Site collection features
– ben
I started from the scratch again and now i see the custom field but data is not getting saved now. I have updated my question with code.
– user346514
Everythings works fine now. I Was not getting the value from the textbox before updating.
– user346514
1 Answers
0
votes
The code is working fine now. Other than the steps mentioned in the articles I also added below code.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// add save handler only in New and Edit modes
if ((SPContext.Current.FormContext.FormMode == SPControlMode.New)
|| (SPContext.Current.FormContext.FormMode == SPControlMode.Edit))
{
SPContext.Current.FormContext.OnSaveHandler
+= new EventHandler(MyCustomSaveHandler);
}
}
protected void MyCustomSaveHandler(object sender, EventArgs e)
{
Page.Validate();
if (Page.IsValid)
{
SPContext.Current.ListItem["CM_x0020_Number"] = TextBox1.Text;
SPContext.Current.ListItem.Update();
}
else
{
// do actions instead of save
}
}