Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Problem in adding a button to a page.

    • 0
    • 0
    • 0
    • 4
    • 0
    • 0
    • 0
    • 485
    Answer it

    Hi guys. I have a problem in adding a button to a page. When I add a simple button to a page and reload the page it loads correctly but when I click on the button I get the following error: "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." What is it about and how can I get rid of it? I am using VS2010 with .Net framework 4.0. Thanks is advanced.

 4 Answer(s)

  • The answer of your question is Yes. In this case, you will have to re-create your dynamic controls in the Page_Init event - which occurs before the ViewState is loaded. You can create controls for the first time in Page_Load - just make sure to recreate them in Page_Init when the page gets loaded again.

    Can you mark answer as Correct if it solves your problem.

  • Dear Chetan.Sharda, Thank you. It worked like a charm. My problem is fixed. But one question: by this way I can get rid of that error, but what would happen if I want to use viewstate somewhere in my code? Can I use it or no?

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: