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