Question

I have built a webpart that basically displays all the items in a SharePoint list based on a set of criteria.

One of these criteria's is a date, a year specifically. The user is supposed to select the date from a dropdown list in the web part and the view area below will populate with all the items from that specific year.

That part works. The SPQuery grabs the data just fine and displays it in the format desired. The issue I am having is with the autopostback option on the dropdownlist.

It doesn't remember the current selectedindex, it remembers the PREVIOUS selected index. If I chooes 2014, the page loads but nothing changes, if I then choose 2013, the 2014 stuff appears, if I then choose 2010, the 2013 items appear, if I go back and then select the 2014, the 2010 stuff appears. It's always 1 behind and I have no idea why.

I've tried assigning a ViewState variable in the SelectedIndexChange to remember what was selected, but that too always seems to be one step behind. I can't seem to get the CURRENT selected index.

Does anyone know what's going on here?

Was it helpful?

Solution

Your question is more ASP.NET problem than SharePoint. Check MSDN to see page life-cycle. New values of controls are available after the onLoad event of Page. So just move your code to e.ge. onPrerender event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top