This is a migrated thread and some comments may be shown as answers.

User Controls in ListView are losing their viewstate

1 Answer 87 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Patrick
Top achievements
Rank 1
Patrick asked on 28 Dec 2011, 05:05 PM
Hi,
 I have custom user controls dynamically added to a RadListView.
 The user controls themselves govern their sub controls user access (hidden, readonly, etc...)
 Although X Controls are Created, X - Y controls remain after the ItemDataBound event is done firing based on the user's access. (where Y is between 0 and X).

The problem is, on Postback the User Controls lose their viewstate... why is this happening?

I can do Everything in the ItemCreated Event and it functions as intended; however, since that is fired on every single Postback it is doing unnecessary calculations going through and figuring out which fields are visible, readonly, and which controls are even part of the List,

Am I stuck doing everything in the ItemCreated Event?

Or is their a way to Just Do my Processing and DataBinding in the ItemDataBound Event? <--(This would work now, if the controls retained their viewstate on postback)

Thanks,
~Patrick

1 Answer, 1 is accepted

Sort by
0
Patrick
Top achievements
Rank 1
answered on 28 Dec 2011, 08:16 PM
My guess is the issue revolved around me removing Controls from the Listview after they were created.

Anyway, I got a hold of the source-code for the custom controls and added ability for an outside source to set their AccessLevel.
I then refined the DataSources for the RadListViews on Page Init to only include controls that would definitely be visible in some way to the user.
I was then able to do everything in the ItemDataBound event and the controls' Viewstates are now persisted, so the heavy-lifting is only done if(!isPostback) w/in the OnInit Page Event. And everything is now functioning as intended and I'm not doing all of the databinding on every ItemCreated Event.

Thanks,
~Patrick
Tags
ListView
Asked by
Patrick
Top achievements
Rank 1
Answers by
Patrick
Top achievements
Rank 1
Share this question
or