Custom field (IUsercontrolDataEditor) blanks out property on save
I've written a custom field following the tutorial at http://www.nibble.be/?p=24. The property the field is rendering is an ID for a node (e.g. 1234), and the field renders the name of that node in a span - the field isn't user editable.
Unfortunately, every time I save and publish a document with the custom field, the property backing that field is blanked out - e.g. "1234" becomes "".
public partial class ReadonlyNodeReference : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor { protected void Page_Load(object sender, EventArgs e) { if (umbracoValue != null) { string valStr = umbracoValue.ToString(); if (!String.IsNullOrWhiteSpace(valStr)) { int val; if (int.TryParse(valStr, out val)) { nodeName.InnerText = getNodeNameFromId(val); } else { nodeName.InnerText = String.Format("Invalid node ID: '{0}'", valStr); } } } } private object umbracoValue; public object value { get { return umbracoValue; } set { umbracoValue = value; } } private string getNodeNameFromId(int nodeId) { if (nodeId > 0) { var n = new Node((int)nodeId); return n.Name; } else { return String.Format("Invalid node ID: '{0}'", nodeId); } } }
OK, fixed it - the problem was that the umbracoValue is cleared in between load and postback. The fix is to save the id in a hidden and then restore it on postback:
Custom field (IUsercontrolDataEditor) blanks out property on save
I've written a custom field following the tutorial at http://www.nibble.be/?p=24. The property the field is rendering is an ID for a node (e.g. 1234), and the field renders the name of that node in a span - the field isn't user editable.
Unfortunately, every time I save and publish a document with the custom field, the property backing that field is blanked out - e.g. "1234" becomes "".
Does anyone know what I'm doing wrong?
Apologies for the bump - I've been looking at the database, and pre-save the value is set (3626), post-save the value is null (NULL).
Pre-save:
Post-save:
OK, fixed it - the problem was that the umbracoValue is cleared in between load and postback. The fix is to save the id in a hidden and then restore it on postback:
is working on a reply...