Note that there are some explanatory texts on larger screens.

plurals
  1. POdynamic controls based on user postback
    text
    copied!<p>Suppose I have a treeview, where each treenode contains an id for a different set of user controls. When the user clicks a node, these controls should be loaded to the page. As I understand the ASP page life cycle, dynamic controls should be added in the initialization stage, and postback events will fire later on.</p> <p>So if the treeview click event happens after I need to add my controls, how do I dynamically add controls based on user postback events?</p> <hr> <p>Edit: I tried the suggestion from ArronLS:</p> <p>What I did was add the node value to the session array, and use that when I do the init to choose which form elements to load to the controls of a placeholder control. On the treeview click event, I update the node in the session array, clear the old form elements in the placeholder, and add the new form elements to the controls. When the page is loaded again, it should now find the node at init time, so viewstate problems would be circumvented.</p> <p>Now I haven't fully tested this yet, but there was another <a href="https://stackoverflow.com/questions/987680/dynamically-change-user-control-in-asp-net">similar post</a> that talks about the problems that might result with the viewstate. They suggest a solution that polls the Request[] part of the context (in their case the dropbox) within the Init control, manually handling some of the postback functionality. </p> <p>My new question is <strong>how to I access the selected node in the treeview using the Request array?</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload