Refresh Vs Postback with Dynamic Controls

Posted on 2004-11-08
Last Modified: 2008-02-01

  I am looking for an explanation of the difference between a postback and a refresh.

  Please a little bit more than the obvious...

  I am looking to solve the following error that I am receiving.

  [HttpException (0x80004005): Failed to load viewstate.
  The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.

  I have closely followed several examples about the whidbey project and several other dynmic control examples.  

  The site for the most part is menu driven with a single page that differring ascx controls are loaded into the body of the page depending on the user selection.

  There are several controls that have a jump to another control.  Essentially removing themselves from the placeholder on the form and replacing with the next control.  This is used for a more fluid transition when values are passed from one screen to another.  Works well .... until someone does a refresh right after the jump.  Performing a postback then a refresh does not incurr the same error and completes successfully.  

  I have played with viewstate values but have not been able to terminate the problem.

  I would like to start with a discussion on the difference between the refresh and the postback if possible.

  I can post example code at a later time.
Question by:dlarlick
    LVL 5

    Expert Comment

    A refresh is when the page is loaded as an request, and uses the GET method. (such as when the page is first loaded by the user).
    A postback is when a form on the page is posted to the server, and uses the POST method.  The server can then interpret any inputs that were on the form.

    When you check Page.IsPostBack, you are asking, "Did the user press a submit button?", or if you have controls set to AutoPostBack, they will post when they are selected (radios, checkboxes, listboxes are onchange).
    LVL 2

    Author Comment


      On a refresh, how is the viewstate traversed,  

      Essentially...  Why would I receive a different behavior from the server than if I had done a postback.  

      can you expand a little on the exact page life cycle differences...

      Thanks for the response.

    LVL 28

    Expert Comment

    Hi dlarlick,

    check this thread ( for your error ) :

    LVL 2

    Author Comment


      mmm not sure......

      don't have a datagrid and only happens on the initial refresh of a page after a new control is swapped into the body.

      I'm rebuilding the controls and should match the viewstate,  I'm baffled why I would error on an initial refresh and not a submit, subsequent refreshes are fine.

    LVL 2

    Author Comment


      I found a qoute from Gary McGlennon, from Visual Studio Magazine, but still am unsure how it may apply to my circumstance as I am reassigning the id of the controls I add to the form.  (unless.. the control id's on the control are affected hmmm...)

      Well any way...  Hope this adds to the direction of my intended discussion.

      "The control state works correctly only on every second postback.  I'll discuss the reasons why.. "  (regarding dynamic controls)
      "The internal counter keeps increasing when you add a usercontrol, but doesn't decreae if you remove one, until it's re-created on postback."
    LVL 2

    Author Comment


      Please remove topic and refund points. PAQ
      No additional knownledge was gained from this thread.

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now