views:

11

answers:

0

I have a ASP.NET web form that implements a wizard using a simple state machine, defined in another class and stored in a session variable. The functions to be executed when different states are reached are defined in the web form class, which passes a delegate array to the state machine during initialization. When the state machine arrives at a new state, the appropriate function is selected from the delegate array and invoked.

The problem is that when the state functions are executed by the state machine, the changes to the UI (panel visibility) are reverted when execution returns from the state machine. For example, after the code in function State1 has been executed, the debugger confirms that Panel1.Visible = True; but after returning from MoveNextState, Panel1.Visible = False.

Any idea how this can be prevented?

Public Partial Class MyWebForm.aspx.vb
...

Private Sub btnNextState_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNextState.Click
 MyStateMachine.MoveNextState()
End sub

Public Function State1() As Boolean
 Panel1.Visible = True
 Return True
End Function

Public Function State2() As Boolean
 Panel1.Visible = False
 Panel2.Visible = True
 Return True
End Function

End Class

Public Class StateMachine
...
<references to functions State1 and State2 stored in delegate array>

Public Function MoveNextState() 
 stateNum = <determine new state>
 DelegateArray(stateNum).Invoke()
EndFunction

End Class