views:

148

answers:

0

Helo!

I have a small problem with CreateChildControls() method. I have a List of items, and each item will have a Button with Click event. Items will be added in Page_Load event.

So for each item in a list, I would like to add a Button with EventHandler like this:

        foreach (Item i in _items)
        {
            Button del = new Button { ID = "del_" + i.ItemText };
            del.Click += new EventHandler(del_button_Click);
            _delButtons.Buttons.Add(del);
            this.Controls.Add(del);
         }

The problem is that when CreateChildControls() is called I don't have the _items list yet (Items are added on Page_Load event).

I can add new Buttons in Render event, but than click event doesn't work(del_button_Click doesn't fire). Any ideas?

So - the question is how to generate a Button for each list item in CreateChildControls() when I don't have the list items yet?

Thank you!