A Bit of Background:
I have been working on a custom data type for Umbraco. The datatype displays a list of nodes of a particular type and allows the user to select from this list. I have attempted to make this data type reusable so that I do not have to create a separate one for each type of node I wish to list. I simply create a property of this data type and set which type of nodes to display.
The datatype is an UpdatePanel that contains of a list of checkboxes (for each node to select) and a button to Add/Remove these nodes to and from the selection.
As an example, if I have a Post, i can add this datatype and set it to list categories, this allows me to associate the post with a list of categories. If i then want to have another instance of this datatype, say to pick Authors, I start running into issues.
DataType Structure Information
This should give some more detail into how this control is built. It used the 3 classes method of creating an umbraco datatype so I do not have a .ascx file, just a .cs file that programatically renders elements onto the page.
The checkboxes are rendered by iterating through a list of Nodes and rendering the following:
<input type='checkbox' name='select_nodes' value='" + n.Id + "' />
I then render two buttons, one to add the nodes to the list of selected nodes, and one to remove them (I am just showing add here). This button simply gets the value of Form["select_nodes"] which contains a comma separated list of node Ids, and for each one, adds it to the list of separate nodes.
The buttons are added as follows:
public override void OnInit(EventArgs e)
{
//Add Button
btn_Add = new Button();
btn_Add.CssClass = "btn_add";
btn_Add.ID = "btnAdd" + Guid.NewGuid();
btn_Add.Text = "Add >>";
btn_Add.Click += new EventHandler(selectNodes);
base.ContentTemplateContainer.Controls.Add(btn_Add);
}
The above describes this control in its basic form, and hopefully provides a bit more insight into the setup.
The Issue
On loading a node with multiple instances of this datatype, as in the example above, errors occur due to duplicate control ids, I overcame this by appending a random guid to the ids. The problem now is that the buttons to select/deselect the nodes do not appear to be working. I'm assuming it is due to there being multiple instances of these buttons, and getting confused with which event to fire?
Is there a way to get around this? To avoid interference across multiple instances of a control?
Thanks,