Problem with ViewState

Discussion in 'ASP .Net Web Controls' started by Matteo Migliore, Apr 27, 2005.

  1. Hi.

    I'm building a custom control
    that contain a property that is a
    custom collection.

    This custom collection return
    as element an object of class A.

    Class A contain a property that is
    of the same type of the collection up.

    The problem is I use ViewState to
    mantain status of the collection but
    at each postback it become null.

    ViewState works well for other
    property of the control.

    I've also tried to serialize the
    collection into a file and works too.


    How to solve?

    Thanks,
    Matteo Migliore.
     
    Matteo Migliore, Apr 27, 2005
    #1
    1. Advertising

  2. Matteo Migliore

    Brock Allen Guest

    When during postback are you trying to access your ViewState? If you try
    to access it in Page_Init, then it will be null, as ASP.NET has not yet reconstructed
    it for you.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi.
    >
    > I'm building a custom control
    > that contain a property that is a
    > custom collection.
    > This custom collection return
    > as element an object of class A.
    > Class A contain a property that is
    > of the same type of the collection up.
    > The problem is I use ViewState to
    > mantain status of the collection but
    > at each postback it become null.
    > ViewState works well for other
    > property of the control.
    > I've also tried to serialize the
    > collection into a file and works too.
    > How to solve?
    >
    > Thanks,
    > Matteo Migliore.
     
    Brock Allen, Apr 27, 2005
    #2
    1. Advertising

  3. Hi Brock.

    > When during postback are you trying to access your ViewState? If you try
    > to access it in Page_Init, then it will be null, as ASP.NET has not yet
    > reconstructed it for you.


    No, I try to access it into OnLoad event.

    For another property (of type of the class A)
    that use ViewState there aren't problem.

    Matteo Migliore.
     
    Matteo Migliore, Apr 27, 2005
    #3
  4. Matteo Migliore

    Brock Allen Guest

    > No, I try to access it into OnLoad event.

    Well, it's odd that it's null for you then. OnLoad should have the ViewState
    reconstructed for you. I suppose without more info on what's going on, I
    can't help in finding out what the problem is.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen
     
    Brock Allen, Apr 28, 2005
    #4
  5. Matteo Migliore

    MasterGaurav Guest

    Can you post the code for:

    1. Attributes to the control class
    2. The property been exposed (type and attributes) as in the main
    control
    3. The methods LoadViewState and SaveViewState
    4. The hierarchy of and attributes to the custom collection class.


    --
    Cheers,
    Gaurav Vaish
    http://www.mastergaurav.org
    http://mastergaurav.blogspot.com
    --------------------------------
     
    MasterGaurav, Apr 28, 2005
    #5
  6. Hi.

    Thank you in advance.

    > Can you post the code for:
    > 1. Attributes to the control class


    The only attribute I used is DesingerAttribute
    but it not useful to solve the problem :-D.

    > 2. The property been exposed (type and attributes) as in the main
    > control


    > 3. The methods LoadViewState and SaveViewState

    I've not implemented.
    I use viewstate in this way:

    public COLLECTION_TYPE Property1
    {
    get
    {
    return ViewState["Property1"] as COLLECTION_TYPE;
    }
    set
    {
    ViewState["Property1"] = value;
    }
    }

    > 4. The hierarchy of and attributes to the custom collection class.

    What I've to post? :-D

    I don't understand.

    Matteo Migliore.
     
    Matteo Migliore, Apr 28, 2005
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Rush
    Replies:
    2
    Views:
    533
    Ben Rush
    Dec 5, 2003
  2. Steph
    Replies:
    2
    Views:
    1,669
    heislord5
    May 11, 2011
  3. ujjc001
    Replies:
    0
    Views:
    1,373
    ujjc001
    Jul 27, 2005
  4. sck10
    Replies:
    6
    Views:
    919
    sck10
    Sep 1, 2006
  5. mark

    Viewstate errors... how do I get viewstate working?

    mark, Feb 20, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    279
Loading...

Share This Page