OK, here's another question for the experts:
I am building a multi-step (3 steps actually) form using a panel for
each step and hiding/displaying the appropriate panel/panels depending
on which step you're on. This all works fine, but I ran into some
trouble when I started creating controls dynamically in my code-behind
file.
Each panel contains a table which is filled with various radio buttons,
text fields and the such which are built in the code-behind file using
table.rows.add, row.cells.add, cell.controls.add, etc.
Originally I was building all of these either in the Page_Load->Not
IsPostBack section of my code-behind (for the initial panel view) and in
the "Next" button Click event handlers for the panels that followed.
This apparently does not work because the ViewState is not maintained.
Dynamic controls must be created in the Page_Load or Page_Init methods
in order for them to be properly filled with the appropriate ViewState.
So now I have all of these panels being built in the Page_Load method
EVERY time the page is loaded (not just the first time). This
definitely works - I'm seeing the results I expected - but it just feels
wasteful to be building all three panels every time I load the page even
though I am only displaying one at a time.
I'd like to be able to only build the one panel I intend to display, but
since the Page_Load occurs prior to the event handling section of a
page's life cycle, I have no way of knowing which button was pushed and
thus which panel is being requested.
So basically I'm wondering the following:
1. Is there a way for me to determine which button was pushed in the
Page_Load method?
2. Regardless of the answer to #1, am I required to load all dynamic
controls each page load to maintain their viewstate even though I may
not be displaying them this particular page load?
3. If I am required to load all dynamic controls, can you explain how
.NET handles this in an efficient manner as at first look it seems like
a lot of additional processing.
4. What best practices are people using when developing multi-stepped
forms with dynamic controls. We have a ton of projects like these and I
want to create a template to be used for the future.
Thanks for all of your time and patience.
Leo Hart
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!