Skip to content

Instantly share code, notes, and snippets.

@csim
Last active August 29, 2015 13:58
Show Gist options
  • Save csim/10280829 to your computer and use it in GitHub Desktop.
Save csim/10280829 to your computer and use it in GitHub Desktop.
SharePoint Field Control
namespace MyProject.Web.UI.FieldControls
{
using System;
using System.Web.UI;
using Microsoft.SharePoint.WebControls;
public abstract class UserControlFieldBase : BaseFieldControl
{
private SPFieldUserControlBase _usercontrol;
public virtual string UserControlPath { get; set; }
public override object Value
{
get
{
return _usercontrol == null ? base.Value : _usercontrol.Value;
}
set
{
base.ItemFieldValue = value;
}
}
public UserControlFieldBase()
: base()
{
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
UserControlPath = null;
}
protected override void CreateChildControls()
{
Controls.Clear();
base.CreateChildControls();
if (!string.IsNullOrEmpty(UserControlPath))
{
_usercontrol = (SPFieldUserControlBase)Page.LoadControl(UserControlPath);
_usercontrol.FieldControl = this;
Controls.Add(_usercontrol);
}
}
}
}
namespace MyProject.Web.UI.FieldControls
{
using System.Web.UI;
public abstract class SPFieldUserControlBase : UserControl
{
protected SPFieldUserControlBase();
public BaseFieldControl FieldControl { get; set; }
public abstract object Value { get; }
}
}
namespace MyProject.Web.UI.FieldControls
{
using System.Web.UI;
public class MyFieldContol : UserControlFieldBase
{
public override string UserControlPath
{
get
{
return "~/_controltemplates/MyFieldControl.ascx";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment