Last active
August 29, 2015 13:58
-
-
Save csim/10280829 to your computer and use it in GitHub Desktop.
SharePoint Field Control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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