Solution: LoadViewState not getting fired in ASP.NET 2.0

A

Anand Saha

In case you are creating your own control dynamically and need
to re-create them on LoadViewState, only to discover that this
function is not being called by the framework, reason and
solution is this:

The LoadViewState function is called by the framework only when
the viewstate object is not null (pretty reasonable).

In the above scenario, SaveViewState might not need to save
anything in the viewstate object, leaving the viewstate object
null - hence the reason why LoadViewState is not being called
in the lifecycle.

A solution to this might be to override the SaveViewState fn,
and add something deliberately to the ViewState like this:

protected override object SaveViewState()
{
this.ViewState.Add("dummy_key","dummy_value");
return base.SaveViewState(); // not null now
}

This will ensure that your LoadViewState() is called.

saha
--
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top