I created a custom macro parameter type that renders a listbox. I've added a parameter of this type to a macro which in turn I'm trying to add to a page using the MacroContainer.
The MacroContainer renders fine, so does the macro and this parameter listbox.
When I select a different value in the listbox and save the document, I get an interesting problem: during the Page_Load, the Value set is called to set the selectedvalue of the listbox to whatever value is already in the db. After this the Value get is called to retrieve the value so it can be saved to the database. Of course this means the new selected value gets overwritten before it is saved.
Anyone have an idea on how I should tackle this, if at all possible?
Below is the code of the custom macro parameter:
public class TestimonialPicker : ListBox, IMacroGuiRendering { protected override void OnLoad(EventArgs e) { base.OnLoad(e); if(this.Items.Count == 0) { // set properties this.SelectionMode = ListSelectionMode.Multiple; // load all testimonials var testimonials = Document.GetDocumentsOfDocumentType(DocumentType.GetByAlias("testimonial").Id); this.DataSource = testimonials; this.DataValueField = "Id"; this.DataTextField = "Text"; this.DataBind(); } } public string Value { get { return this.SelectedValue; } set { this.SelectedValue = value; } } public bool ShowCaption { get { return true; } } }
This is the stacktrace at the moment the setter for Value is called:
if (_umbval != null) { if (!string.IsNullOrEmpty(_umbval.ToString())) { foreach (var id in _umbval.ToString().Split(',')) { var listitem = ListBox1.Items.FindByValue(id); if (listitem != null) listitem.Selected = true; } } } } }
public object value { get { .... return selectedValues; } set { _umbval = value.ToString(); } }
Custom macro parameter type and MacroContainer
Hey guys,
I created a custom macro parameter type that renders a listbox. I've added a parameter of this type to a macro which in turn I'm trying to add to a page using the MacroContainer.
The MacroContainer renders fine, so does the macro and this parameter listbox.
When I select a different value in the listbox and save the document, I get an interesting problem:
during the Page_Load, the Value set is called to set the selectedvalue of the listbox to whatever value is already in the db.
After this the Value get is called to retrieve the value so it can be saved to the database.
Of course this means the new selected value gets overwritten before it is saved.
Anyone have an idea on how I should tackle this, if at all possible?
Below is the code of the custom macro parameter:
> UmbracoExtensions.DLL!UmbracoExtensions.AppCode.TestimonialPicker.Value.get() Line 36 C# umbraco.editorControls.DLL!umbraco.editorControls.macrocontainer.MacroEditor.CreateUmbracoMacroTag() + 0x1ae bytes umbraco.editorControls.DLL!umbraco.editorControls.macrocontainer.Editor.Save() + 0x386 bytes umbraco.DLL!umbraco.controls.ContentControl.saveClick(object Sender, System.Web.UI.ImageClickEventArgs e) + 0xb9 bytes umbraco.DLL!umbraco.controls.ContentControl.savePublish(object Sender, System.Web.UI.ImageClickEventArgs e) + 0x18 bytes System.Web.dll!System.Web.UI.WebControls.ImageButton.OnClick(System.Web.UI.ImageClickEventArgs e) + 0xbb bytes System.Web.dll!System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(string eventArgument) + 0xa5 bytes System.Web.dll!System.Web.UI.Page.ProcessRequestMain(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint) + 0xe7b bytes System.Web.dll!System.Web.UI.Page.ProcessRequest(bool includeStagesBeforeAsyncPoint, bool includeStagesAfterAsyncPoint) + 0xc1 bytes System.Web.dll!System.Web.UI.Page.ProcessRequest() + 0x10d bytes System.Web.dll!System.Web.UI.Page.ProcessRequest(System.Web.HttpContext context) + 0xa7 bytes App_Web_editcontent.aspx.5f2dec3.9szaexj4.dll!ASP.umbraco_editcontent_aspx.ProcessRequest(System.Web.HttpContext context) + 0x32 bytes System.Web.dll!System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() + 0x271 bytes System.Web.dll!System.Web.HttpApplication.ExecuteStep(System.Web.HttpApplication.IExecutionStep step, ref bool completedSynchronously) + 0x10e bytes System.Web.dll!System.Web.HttpApplication.PipelineStepManager.ResumeSteps(System.Exception error) + 0x6f5 bytes System.Web.dll!System.Web.HttpApplication.BeginProcessRequestNotification(System.Web.HttpContext context, System.AsyncCallback cb) + 0x85 bytes System.Web.dll!System.Web.HttpRuntime.ProcessRequestNotificationPrivate(System.Web.Hosting.IIS7WorkerRequest wr, System.Web.HttpContext context) + 0x2b6 bytes System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr managedHttpContext, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) + 0x3bf bytes System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr managedHttpContext, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) + 0x22 bytes [Native to Managed Transition] [Managed to Native Transition] System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotificationHelper(System.IntPtr managedHttpContext, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) + 0x4f4 bytes System.Web.dll!System.Web.Hosting.PipelineRuntime.ProcessRequestNotification(System.IntPtr managedHttpContext, System.IntPtr nativeRequestContext, System.IntPtr moduleData, int flags) + 0x22 bytes [Appdomain Transition]*UPDATE*
found following workaround:
private string _umbval;is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.