Home All Groups Group Topic Archive Search About
Author
27 Apr 2005 7:49 PM
Matteo Migliore
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.

Author
27 Apr 2005 9:38 PM
Brock Allen
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



Show quoteHide quote
> 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.
Author
27 Apr 2005 9:51 PM
Matteo Migliore
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.
Author
27 Apr 2005 11:25 PM
Brock Allen
> 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
Author
28 Apr 2005 5:27 AM
MasterGaurav
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
--------------------------------
Author
28 Apr 2005 2:08 PM
Matteo Migliore
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.
Author
12 May 2005 5:34 PM
vMike
Show quote Hide quote
"MasterGaurav" <gaurav.va***@gmail.com> wrote in message
news:1114666067.739955.136320@g14g2000cwa.googlegroups.com...
> 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
> --------------------------------
You might try adding this bit of code to your page.

Protected Overrides Function SaveViewState() As Object
  Return MyBase.SaveViewState()
End Function

Protected Overrides Sub LoadViewState(savedState As Object)
   If Not (savedState Is Nothing) Then
      MyBase.LoadViewState(savedState)
   End If
End Sub