views:

42

answers:

2

All

I am having with what appears to be a ASP.NET page life cycle issue. I currently have a user control embedded into my page. Now depending on the options chosen from the menu item list, the page can be in one of three states represented by a PageStates Enum within the control. The page on selecting the menu item merely updates the a property exposed from the control

  • Initial State (nothing congifurable)
  • Editing (this uses a dropdown extender and makes a gridview within it visible)
  • Adding (this uses another dropdown extender and makes the same the gridview visible however with different properties)

PROBLEMS

  1. The page will only get itself into the correct 'state' if the menu item is selected twice
  2. Controls are visible on the gridview when they shouldn't be
  3. The page 'state' seems to lag one state behind

I think the main problem I having with this is that the grid view has check boxes drawn if the page is Adding mode, however you would need to select the Adding menu item option twice to get it into this state and I believe it is because I am setting the page state when the menu item is selected however the grid rows are already created at this point ( I am dynamically creating the check boxes in the grid view within the RowCreated event

Does anyone have any suggestions as to how I get round this problem? Can this implementation ever work?

+1  A: 

If your control is triggering things that change the state, and you are redrawing the the page_load event, then your state will not be updated until the control event has fired. To moving the page construction to the page_prerender or similar event in the lifecycle.

If you need more help on what order page events are firing in, add Trace="true" to the page directive in your aspx page.

ck
A: 

I managed to solve this in the the following manner.

The underlying problem was that I was creating my check boxes on the RoWCreated event which was happening before the page State was being updated.

So I created my own sub called createCheckBoxes which was called when the page State was changed correctly.

This has solved my problem with minimal performance overheads from my initial investigations

Dean