I have two ListBoxes in a DetailsView that are visible only in Edit mode, lbAllPeople and lbSelectedPeople. I am populating lbSelectedPeople in its OnLoad event based on data in SQL Server.
The user can select a person from lbAllPeople and click an Add button, which adds the ListItem to lbSelectedPeople and also causes a postback. The OnLoad event for lbSelectedPeople fires again and executes all its code, which I don’t want it to do; I want the code to execute only the first time it loads.
I can’t use if (!IsPostBack) because the original load does occur in a PostBack.
I’ve tried setting a public Boolean that says the page is already loaded, but the value of that Boolean doesn’t persist when the page is posted back ... I’m setting it to true in the OnLoad event but it gets set back to false before the Add button is clicked. I don’t understand why.
Thanks for any help!