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:
*UPDATE*
found following workaround:
private string _umbval;
is working on a reply...