|
I have an ASP application I'm working with in Visual Studio 2008 where one of the requirements is to assign contacts to a facility. There is a dialog where you can define contacts so you have ListBox1 with your previously defined contacts and ListBox2 with the contacts you want to assign. So there is a << and >> button to add and remove contacts. In updating this application to 9.3 we changed the architecture to be less GISsentric and more business oriented. This meant for this portion of the application could now use updatepanels and server side logic rather than a boat load of javascript.
I figured this would be easy, put the listbox's inside an updatepanel along with the buttons, write some code to remove one and add it to the other. I wrote the code first to work outside the updatepanel and then I would add it in when I was satisfied it was working.
The first problem was me being forgetful. When I was selecting my listitem to move and clicking the button the selectedIndex was always -1. Well the ASP page lifecycle goes through page_load and was rebinding my control through the LINQ to SQL code I wrote. Therefore there is no selected item since the items are all new. Quick fix, put the LINQ code inside a if (!Page.IsPostBack){} statement so it doesn't get run.
Second problem arouse when I got an error saying, "Cannot have multiple items selected when the SelectionMode is Single." This was happening since the item being added to the Listbox was selected to be moved over. The error only comes up the second time you add a new ListItem since both items are selected. Easy fix again, set the listitem.selected property to false before adding it.
The weirdness happened when I tried putting the ASP xml markup inside the updatepanel's content template. In firefox I was getting duplicate rendering. So I'd end up with 4 buttons and 4 ListBox's. Not ideal. I decided to put each listbox in it's own update panel and now everything works like a charm.
|