Server.Execute to a form, Response.Redirect back.  The View State is invalid for this page and might be corrupted

Posted on 2005-05-02
Last Modified: 2010-05-18
I'm using Server.Execute to process a second web form
    System.IO.StringWriter swrTarget = new System.IO.StringWriter();
This brings up the second form just fine.

Then I use a button to return to the 1st form

When I do so, I get "The View State is invalid for this page and might be corrupted."
[HttpException (0x80004005): The View State is invalid for this page and might be corrupted.]

Both forms have EnableViewStateMac="false" in their aspx.  The second form does a Response.Write, but commenting it out does not fix the problem.  WebForm1 and WebForm2 are the correct case-sensitive names.  This is a very simple program -- I'm studying the Microsoft MCAD/MCSD book (Chapter 4, Lesson 3).  

I'm stuck.  Can someone help?

Thank you.
Question by:josgood
    LVL 96

    Expert Comment

    by:Bob Learned
    With Server.Execute the page executes like a subroutine.  If you want control to pass to the new form, use Server.Transfer instead.

    LVL 23

    Expert Comment

    Response.Redirect is just telling the client browser to load the page from scratch, so no form elements are posted, therefore, no ViewState is to be reconstructed as there is no postback occurring.

    something else is happening.,
    LVL 96

    Accepted Solution

    The Execute Method:

    The Execute method executes an ASP file from inside another ASP file. After executing the called .asp file, the control is returned to the original .asp file.


    LVL 13

    Author Comment

    Thank you, Bob.  That's a good distinction to make.

    To me, it seems that Server.Execute is more like starting another thread.  The Server.Execute returns immediately -- it does not wait for the new form to open, be processed, and then close.  Both the initial and second pages are active.

    I'm using Server.Execute because that's what the book is covering in the section I'm reading.
    LVL 13

    Author Comment

    I just looked at the link provided by The Learned One.  That told me exactly what I needed to do to debug this problem -- Response.Write in both forms.  Just like using printf in the old days.

    If I change
    then everything works great!

    Don't know what the swrTarget is a problem, but that's another question.

    Thank you for providing the way to find the solution, Bob.  That's much more valuable than just the answer!  Full marks.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now