User Controls in ListView are losing their viewstate

2 posts, 0 answers
  1. Patrick
    Patrick avatar
    29 posts
    Member since:
    May 2011

    Posted 28 Dec 2011 Link to this post

    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
  2. Patrick
    Patrick avatar
    29 posts
    Member since:
    May 2011

    Posted 28 Dec 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top