Problem with ViewState

M

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.
 
B

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.
 
M

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.
 
B

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.
 
M

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top