Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8738415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:43:40+00:00 2026-06-13T10:43:40+00:00

The problem is, i need to persist ViewState during a CallBack request. I know

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:43:41+00:00Added an answer on June 13, 2026 at 10:43 am

    Finally got it.

    Here’s the thing.

    After some decompiling of the Page class (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 method ProcessRequestMain:

    this.Trace.Write("aspx.page", "Begin PreInit");
    this.PerformPreInit();
    this.Trace.Write("aspx.page", "End PreInit");
    this.Trace.Write("aspx.page", "Begin Init");
    this.InitRecursive((Control) null);
    this.Trace.Write("aspx.page", "End Init");
    this.Trace.Write("aspx.page", "Begin InitComplete");
    this.OnInitComplete(EventArgs.Empty);
    this.Trace.Write("aspx.page", "End InitComplete");
    
    if (this.IsPostBack)
    {
        this.Trace.Write("aspx.page", "Begin LoadState");
        this.LoadAllState();
        this.Trace.Write("aspx.page", "End LoadState");
        this.Trace.Write("aspx.page", "Begin ProcessPostData");
        this.ProcessPostData(this._requestValueCollection, true);
        this.Trace.Write("aspx.page", "End ProcessPostData");  
    }
    
    this.Trace.Write("aspx.page", "Begin PreLoad");
    this.OnPreLoad(EventArgs.Empty);
    this.Trace.Write("aspx.page", "End PreLoad");
    this.Trace.Write("aspx.page", "Begin Load");
    this.LoadRecursive();
    this.Trace.Write("aspx.page", "End Load");
    
    if (this.IsPostBack)
    {
        this.Trace.Write("aspx.page", "Begin ProcessPostData Second Try");
        this.ProcessPostData(this._leftoverPostData, false);
        this.Trace.Write("aspx.page", "End ProcessPostData Second Try");
        this.Trace.Write("aspx.page", "Begin Raise ChangedEvents");
        this.RaiseChangedEvents();
        this.Trace.Write("aspx.page", "End Raise ChangedEvents");
        this.Trace.Write("aspx.page", "Begin Raise PostBackEvent");
        this.RaisePostBackEvent(this._requestValueCollection);
        this.Trace.Write("aspx.page", "End Raise PostBackEvent");
    }
    
    this.Trace.Write("aspx.page", "Begin LoadComplete");
    this.OnLoadComplete(EventArgs.Empty);
    this.Trace.Write("aspx.page", "End LoadComplete");
    
    if (this.IsPostBack && this.IsCallback)
        this.PrepareCallback(callbackControlID);
    else if (!this.IsCrossPagePostBack)
    {
        this.Trace.Write("aspx.page", "Begin PreRender");
        this.PreRenderRecursiveInternal();
        this.Trace.Write("aspx.page", "End PreRender");
    }
    
    ...
    
    if (this.IsCallback)
    {
        this.RenderCallback();
    }
    else
    {
        if (this.IsCrossPagePostBack)
            return;
    
        this.Trace.Write("aspx.page", "Begin PreRenderComplete");
        this.PerformPreRenderComplete();
        this.Trace.Write("aspx.page", "End PreRenderComplete");
        this.BuildPageProfileTree(this.EnableViewState);
        this.Trace.Write("aspx.page", "Begin SaveState");
        this.SaveAllState();
        this.Trace.Write("aspx.page", "End SaveState");
        this.Trace.Write("aspx.page", "Begin SaveStateComplete");
        this.OnSaveStateComplete(EventArgs.Empty);
        this.Trace.Write("aspx.page", "End SaveStateComplete");
        this.Trace.Write("aspx.page", "Begin Render");
    
        if (exportedWebPartID != null)
            this.ExportWebPart(exportedWebPartID);
        else
            this.RenderControl(this.CreateHtmlTextWriter(this.Response.Output));
    
        this.Trace.Write("aspx.page", "End Render");
        this.CheckRemainingAsyncTasks(false);
    }
    

    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:

    if (this.IsCallback)
    {
        this.RenderCallback();
    }
    else
    {
        ...
        this.SaveAllState();
        ...
    }
    

    So that is the reason my ViewState does not get saved on a CallBack request!

    So, finally, the solution! Call manually the SaveAllState() method using reflection!

    if (Page.IsCallback)
    {
        System.Reflection.MethodInfo saveAllStateMethod = typeof(System.Web.UI.Page).GetMethod("SaveAllState", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
        saveAllStateMethod.Invoke(Page, null);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem: I need to ensure that a particular directory hierarchy exists in the
I have the next problem: I need to process only 1 request at a
I have a simple entity, Code, that I need to persist to a MySQL
Problem I'm trying to create an CUDA application that is well integrated with .net.
Disclaimer: I have read the ASP.net page life cycle , and I've also read
Goal: Gain datatype date with year and month Problem: Need to help to convert
Problem: I need to write/read objects from a file.This because I need to write/read
My problem : I need to create draggable widgets (here it's a jslider for
To solve some problem I need to compute a variant of the pascal's triangle
I faced a problem - I need to use a macro value both as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.