GridView Footer controls not retaining viewstate

T

Tim Royal

I'm using a GridView inside a Wizard Control with a textbox and two
listboxes in the footer. I populate these listboxes from the database if the
page isn't on postback (and the textbox is left blank initially). All of
these controls have viewstate enabled.

When the user fills out the textfield and clicks ADD, I do a check for
validation of the data. If the user does not select a valid listbox entry, I
abort the rest of the add, and make visible a label that tells them what
they need to select (Yes, I know of validators, but had horrendous issues
with them in conjunction with the gridview and wizard).

The problem is that when this situation occurs, the textbox is cleared, and
the two listboxes are empty (no viewstate). I was under the impression that
if I had viewstate enabled, this information would be retained.

Am I missing something? Any insight appreciated.

Tim
 
R

Rupam Srivastava

Hello Tim.

I had been struggling with a similar problem and GOD knows how many hours I
just wasted on it.

Basically, I have come to realize that Gridview footers are not very good at
handling controls like listboxes and dropdownlists.
There are 2 ways you can go ahead.

1) Put your sqldatasource (the one to which you have bound your listbox to),
within its Update Panel, rather than outside it.
For some reason, I have seen that even if there is an async postback, the
listbox / dropdown list experience problems if the sqldatasource they are
bound to is outside the update panel.

2) If 1) does not work, then you have got no option but to remove both
EmptyDataTemplate and Footer template from grid views and put your listbox
and textbox outside the grid and then follow the rest of your logic as usual.
But make sure that you still put your sqldatasource within the containing
update panel.

Hope this helps.
 
T

Tim Royal

Still rather curious if anyone has run into this. We went live anyway, since
it didn't stop the ability of users to complete the wizard. Still, I'd love
to know why when viewstate is enabled, these dynamically added controls do
not retain their settings after postback.

Tim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top