Click to See Complete Forum and Search --> : Postback Refresh Problem


Scott MacMaster
January 24th, 2008, 05:03 PM
I'm working on a page that will be used for configuring users. Of course all the controls will be dynamic since the list of users will be dynamic.

I have a expand button next to each user which when clicked shows options for the users.

Within the options sections, which is a table, I have a "user type" drop down. I have the drop down do an autopost back. In the post back I update another drop down with a list of "subtypes" for the selected "user type".

The problem I have is with the "user type" drop down. It can't seem to remember the selected index and I can't get it to link with the SelectedIndexChanged event handler. I've spent hours reading blogs and other things. Tried everything I can think of. The most common thing I read had to do with making sure I add the dynamic controls before setting a properties.

That seems unlikely since none of my controls are added before I set their properties and they are work fine except my drop down.

In the Init() function I query the database for the list of users and settings. Then I create all the controls I could need and put them in a custom data structure. Basically I a sorted_list of User objects.

In Load() I create the table by looping through my user list and adding the controls I need. Most are not added since only one user can be expended at a time.

I really don't see why the DropDownList would not work when everything else does. Maybe there's a setting I missed or something else. Does anyone have any ideas?



Thanks,
Scott MacMaster

TheCPUWizard
January 24th, 2008, 06:21 PM
Dont have any reution for you, but have you considered switching to an AJAX based design? It will avoid 90%+ of this type of problem.

Scott MacMaster
January 25th, 2008, 11:01 AM
I haven't given AJAX much thought. The company I work for upgraded their 20 year old servers to the latest technology. Everything was programmed in cobol. They hired me to convert 20 years worth of inhouse programming. Their previous programmer quit 6 months after I started. So I'm pretty much on my own in figuring out all the undocumented business logic and converting dozens of programs. In my opinion anything involving javascript takes longer to do so I haven't considered using AJAX. I have plans of going back and using AJAX to make things look nicer. However, right now I really don't know anything about AJAX.

Anyway, I did manage to track down the problem. It's amazing such a stupid mistake could take hours to track down. I suppose it was because I assumed it was a dynamic control issue.


For Each kvp As KeyValuePair(Of Integer, UserType) In UserTypes
Dim currentType As UserType = kvp.Value

user.lstUserTypes.Items.Add(New ListItem(currentType.Name, currentType.TypeId))
Next


I eventually noticed that currentType.TypeId was equal to nothing. Appearantly I forgot to add the line to my constructor for my UserType object that copies the id passed to it to the TypeId member.


Thanks,
Scott

Yeorwned
January 25th, 2008, 04:09 PM
If you're using Visual Studio and ASP.NET 2+, then you can get the AJAX control library and essentially have a fully AJAX enabled application and never write a single line of javascript...the additional effort is negliable if you're rewriting anyway, and well worth it.

dglienna
January 26th, 2008, 11:39 AM
Check it out here http://www.asp.net/ajax/

aamador
January 27th, 2008, 04:34 AM
Post some code! I ran a few quick test and I see no problem at all with the DropDown. Maybe you disabled viewstate and are data binding using a DataSource control. I seen some weird stuff at times but post code it the sure fire way to get to the root of your problem.