The problem
Ok, let's see if I can explain my problem accurately.
The situation:
My page have two controls, a treeview and a placeholder. The placeholder will contain one or more custom controls (basicly a customized Datagrid).
How it works:
The user can navigate through the TreeView Nodes, and when he click in determinate branches, the program add some number of custom controls to the PlaceHolder (depending on some internal logic). When he click another node, the Placeholder is cleared and charged with some new customized datagrids. In the Datagrids there are Image Buttons that, when you click on it, executes a database update and changes the ImageURL of them.
The problem:
When I start to navigate, everything works fine. I click on a node, the datagrids appear, I click one of the ImageButtons and the logic executes correctly. But when I try to charge the customized controls that corresponds to another TreeNode, the event from the ImageButton doesn't fire.
The cause of the problem:
When the page load after the second click on the treenode, I reload the PlaceHolder with the previous customize controls in Page_Load, then the subroutine fired by the SelectedIndexChange of the treeview executes and try to reload again the Placeholder.
First of all I try to clear the Placeholder with a Controls.Clear(), and then recharge it. Visually, that worked and I can see only the controls desired, but programatically, it doesn't work. If I look in the Trace information of the loaded page, the controls inside the placeholder started with and index _ctlX (where X is some number <> 0) insted of starting with the _ctl0 as it should be. This X depends on how many controls have been charged in the Page_Load. If 5 controls have been added in Page_Load, in the event handler of OnSelectIndexChange the first control added has the index _ctl5.
What I am trying to achieve:
If I can detect, in the Page_Load, that an OnSelectedIndexChange event has been fired, I can avoid the first Placeholder charge, and this will solve my problem
I Hope that my explanation was clear, my english is not very good, sorry.