Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason your events aren't happening is because you are misunderstanding the ASP.Net page lifecycle. When you request a page, ASP.Net creates a new instance of the corresponding page class. This instance knows nothing about any other instances that have been created in the past. It uses the instance of the Page class to generate a bunch of HTML, which it sends back to the browser as a response. That instance of the Page class on the server is then destroyed, along with its state.</p> <p>When a page posts back, ASP.Net reads through using the viewstate, ids etc and maps the HTML elements posted back to it to the server controls in your newly created Page instance. The elements you added to the Controls collection of the previous instance don't exist in this new instance, and so ASP.Net cannot recognise them, or fire events on them.</p> <p>Here is an article that demonstrates the kind of thing I think you are trying to achieve, albeit with GridViews, it uses a similar approach to the solution I previously posted.</p> <p><a href="http://www.codeproject.com/KB/aspnet/MultiNestMDGridview.aspx" rel="nofollow">http://www.codeproject.com/KB/aspnet/MultiNestMDGridview.aspx</a></p> <p>Perhaps you could explain exactly what the end goal is, because there might be a better solution? I fully accept that the limitation of both the approach I posted earlier and the solution in that link is that there are a finite number of levels of detail available, which may or may not be a problem depending on what you're actually trying to do.</p> <p>Edit--</p> <p>If you change to the Page_Init event as @Microgen suggests, remove the if (!Page.IsPostBack), set AutoPostBack=true, and use a non-volatile ID for your dynamically added control, this will call the server side event and render the 2nd listbox. It won't work with Guid.New() because the Controls collection on the newly created Page won't contain anything with matching ID so the event handler won't get hooked up. This would answer the question as originally posted. However, your 2nd listbox won't fire events unless you create it and add it to Page.Controls in Page_Init in the same way and so on for the 3rd etc, all for the reason described above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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