The problem is, i need to persist ViewState during a CallBack request.
I know that ASP.NET by default doesn’t save the page state when the request is a CallBack.
So, i would need an alternative to make it work.
The ASP.NET application has a custom PageStatePersister, where it stores all the Page State (ViewState) to the Session. This way the ViewState isn’t sent/retrieved to the client in any moment (although the hidden field still exists on the page, but without value). The ViewState doesn’t have to be returned on the CallBack response, i just need to invoke somehow the mechanism that saves the ViewState on a normal PostBack request.
It would be something like:
protected void Page_LoadComplete(object sender, EventArgs e)
{
//Set anything to the viewstate for accessing on a later postback
ViewState["Anything"] = 1;
if (Page.IsCallback)
{
//Persist the page state manualy (not needed on normal postback)
InvokeAspNetStateSaver();
}
...
}
Appreciate your help.
Finally got it.
Here’s the thing.
After some decompiling of the
Pageclass (System.Web.UI), i found basically what ASP.NET does in the request handling including the state loading and saving. The following code is what ASP.NET does on the methodProcessRequestMain:The Method
LoadAllState()is the responsible for loading the page state, it executes every PostBack request.The Method
SaveAllState()is the responsible for saving the page state. ASP.NET executes it like the following code:So that is the reason my
ViewStatedoes not get saved on aCallBackrequest!So, finally, the solution! Call manually the
SaveAllState()method using reflection!