Refresh Vs Postback with Dynamic Controls

  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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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).
dlarlickAuthor Commented:

  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.

Hi dlarlick,

check this thread ( for your error ) :

Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

dlarlickAuthor Commented:

  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.

dlarlickAuthor Commented:

  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."
dlarlickAuthor Commented:

  Please remove topic and refund points. PAQ
  No additional knownledge was gained from this thread.
PAQed with points refunded (500)

Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.