Here is the idea: a tree view with nodes. Once a node is clicked, the server generates a panel with some buttons specific for that node. Those buttons once clicked (Click event postback) call the event handler on the server. Basically dynamically created nodes with postbacks after being clicked create buttons with postbacks.
Here is my approach: I have a RadTreeView with some data. The RadTreeView has a "OnNodeClick" event handler that gets the actual clicked node. Then the server generates dynamically buttons on a panel based on the value in the node. Problem is that the "OnNodeClick" event handler is fired after the page load and therefore the postbacks from the buttons are not bound. So I tried another approach by adding the selected node value to the ViewState and then reading from it at Page_Load, but the problem is still the same. The chain is Page_Load -> OnNodeClicked, so the ViewState gets set only after the controls have been generated and therefore only on a second Page_Load I can actually get the value.
Some code to make it clear:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
InitTreeNodesFromServices(resourceTree);
}
var resourceIdObj = ViewState["ResourceId"];
if(resourceIdObj != null)
GenerateButtonsForSelection((string)resourceIdObj);
}
protected void resourceTree_OnNodeClick(object sender, RadTreeNodeEventArgs e)
{
ViewState.Add("ResourceId", e.Node.Value);
}
I know it's a simple issue, but I have been stuck with it for a whole day at this point. What is the right way to handle this situation? Maybe I need a different approach? Thank you.