Custom DataType using UserControl lose value after postback
Hi, Guys.
I'm using Umbraco 4.7.1.1 for the website development. While I was developing a custom data type using the UserControl, I found that, after the postback event, the field data disappeared.
public partial class MemberTypePicker : System.Web.UI.UserControl, umbraco.editorControls.userControlGrapper.IUsercontrolDataEditor { #region Properties public object value { get; set; } #endregion #region Event Handlers protected void Page_Load(object sender, EventArgs e) { if (this.IsPostBack) { this.value = this.MemberTypes.Text; } this.MemberTypes.Text = "Administrator"; }
When you guys look at the code above, it is the typical and simple way of creating a custom data type user control. The TextBox control, MemberTypes, is forced to have the "Administrator" value. However, once I click the save button, the MemberTypes.Text lose its value to String.Empty.
Can anyone let me know what I have missed? I've implemented several custom data type user controls so far, but it's my first time to face this issue.
Custom DataType using UserControl lose value after postback
Hi, Guys.
I'm using Umbraco 4.7.1.1 for the website development. While I was developing a custom data type using the UserControl, I found that, after the postback event, the field data disappeared.
When I run the debug mode, I could get the result above, there's nothing!
Hi,
The way I have handled in the past is to create a class in App_Code that extends from ApplicationBase. Add some events, as follows:
public Document Document { get; set; }
public CustomEvents()
{
Document.AfterPublish += Document_AfterPublish;
Document.New += Document_New;
}
private void Document_AfterPublish(Document document, umbraco.cms.businesslogic.PublishEventArgs e)
{
// check to see if this is the right DocType firing the event, read the property, and persist
if (document.ContentType.Alias == "MemberTypePicker") documentTitle = document.Text;
umbraco.library.UpdateDocumentCache(document.Id);
}
Essentially, your document has the value when raising the event, and you read it, then save it to Umbraco. Hope this helps.
is working on a reply...