Dictonary Values lost during Postback

Last post 06-16-2009 9:27 AM by Ambran. 1 replies.

Sort Posts:

  • Dictonary Values lost during Postback

    06-16-2009, 9:15 AM
    • Member
      2 point Member
    • Utsav
    • Member since 03-08-2009, 6:14 AM
    • Ahmedabad
    • Posts 6
    Hi Everyone, I am storing values in a Dictionary variable which has been initialized during PageLoad (inside if(!IsPostbak){}). The dictonary stores values in it whenever ObjectDataSource's Selected Event is fired. Then on every DropdownList's SelectedIndexChange event I want to access the values stored in Dictionary. BUT IT IS SHOWING ME AS "NULL". Why is it so ? How can I retain values in the Dictionary. Thanks in advance. Utsav Acharya Ennovate Technologies, Einfochips, Ahmedabad.
    Utsav Acharya
    Software Engineer
    Ennovate Technologies
    eInfochips
  • Re: Dictonary Values lost during Postback

    06-16-2009, 9:27 AM
    Answer
    • Participant
      1,375 point Participant
    • Ambran
    • Member since 03-18-2009, 10:23 AM
    • Denmark
    • Posts 265

    Hi Utsav

    Because the page is generated at the server and sent to the browser on every postback the dictionary is created newly on every postback.

    What you have to do is to save the dictionary values in ViewState, end reload the dictionary from ViewState after postback. ViewState saves the values localy on the client, so the data is not lost on postback, you just have to reassign the data to the dictionary.

    Amit

    If this post was of any help to you, Mark it as Answer for the benefit of others, Thanks.

    Spread Firefox Firebug - Web Development EvolvedMom's online gallery Mom's grafical oasis
Page 1 of 1 (2 items)