This is a migrated thread and some comments may be shown as answers.

[Solved] ASP.NET Control lifecycle problem

0 Answers 95 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Aleksei Rodionov
Top achievements
Rank 1
Aleksei Rodionov asked on 08 Feb 2008, 07:11 PM
I have two buttons, dynamically added to the page with OnClick event handler assigned to them. I want to place on page one of two different user controls at runtime when a corresponding button click occures. But here I meet the vicious circle: I can't add user control in OnLoad event handler of page, because I don't know which button have been pressed (event handling takes place after OnLoad). Also I can't add the user control after event handling (i.e. in OnPreRender), because in such case none of user control children event handlers  would be fired (there would be no such child controls in moment where event handling occures - between OnLoad and OnPreRender). I've found 2 workarounds to this problem:

  1. I can parse Request.Form collection in OnLoad to determine event sender and command argument and create corresponding user control.
  2. I can add controls guided by previous page state in OnLoad, then if a button click have occured, remove inproper and add proper controls to the page in click handler.
Both of them are inappropriate for me. Could you give me your advice, please?

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Aleksei Rodionov
Top achievements
Rank 1
Share this question
or