The state information is invalid for this page and might be corrupted. (Only in IE)

Can anybody help me out with this exception. I have tried couple of fixes but nothing worked. I am getting this exception only in IE(7, 8 and 9).

When i load the page first time, it brings up a dropdown. where i select a specific vendor and it makes a page post back and returns the required information. If i change the vendor it will still load the information. When i load a control onto page using $.ajax request dynamically and than go back and change the dropdown selection(select a different vendor), it craps out and gave me the following exception. Again it only happens in the IE.

The state information is invalid for this page and might be corrupted. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The state information is invalid for this page and might be corrupted.

Source Error: 


[No relevant source lines]


Source File: c:UserstmalikAppDataLocalTempTemporary ASP.NET Filesroot6691c708751e6443App_Web_a3kdfsht.2.cs    Line: 0 

Stack Trace: 


[FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or a non-white space character among the padding characters. ]
   System.Convert.FromBase64String(String s) +0
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +77
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
   System.Web.UI.HiddenFieldPageStatePersister.Load() +147

[ViewStateException: Invalid viewstate. 
    Client IP: 127.0.0.1
    Port: 
    Referer: http://localhost:57289/vendor.aspx
    Path: /vendor.aspx
    User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; MDDR)
    ViewState: 2D1IMRanPXfVARbRp1ooiwD71WHybNzxSNLbbA0G3MxKeo7m52dHWLBPGdnMH5JthTnPVt7UES/PVx39dfZYHbr0/DL7J58mvA2I4wRUSdDShVxvZqC7ZPZWcatowpZ7VYaD9PFKW7OkgppCwmePFuYnpU8kWDT5TvSLqN50Flrqpv0zCM9YoCKemfesa68rqBkkSTijcxnxdDCgvzSl72giI4ZhwK92wD22Ma6scW4PFjRZeTsKoowJq+JqJGuBMEepwKguFUy4dX86UIULnJ7NQsgZW1aQvpZdnfSRCSYrWhFWPhKTPsS622eaQYShsxddPs/mfEB26f54WS+iBYuk3mWm8jr6sWvsOIRtwH8b3E/5UujbgAxTNVg8BhzpSFvmE4KwGKo0tKuuqOFtP0pjpaAI7fV3EQ1M7BVQSAVrtBevRFJ0PlCPrU2aQms2LVeE5POqTJGtY+74xWkdCtLzT04Ug4R+SMBRElQBqX/5A54OHj2ghYjJ/3tgg4ToGUX2xrQ/c70lrphP+kabGVM2Op4DFjZAaOZj/CDVUurH2BYXKuJdUvzbf2zHngoOnqZGqrw3n6V6HGcnHNKxfuGQ20MPdxJYCbYHGiRqixzV1NxJoHFHbYCVx3IlrqF0W44AFKm2gzzk3V8zu9lUjyFNvUNBMjNaZeekLtcWpszhKrm8WhVnWQAk1CXxKJqyK0RC3...]

[HttpException (0x80004005): The state information is invalid for this page and might be corrupted.]
   System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +235
   System.Web.UI.ViewStateException.ThrowViewStateError(Exception inner, String persistedState) +14
   System.Web.UI.HiddenFieldPageStatePersister.Load() +251
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +106
   System.Web.UI.Page.LoadAllState() +43
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +8431
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +253
   System.Web.UI.Page.ProcessRequest() +78
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +49
   ASP.vendor_aspx.ProcessRequest(HttpContext context) in c:UserstmalikAppDataLocalTempTemporary ASP.NET Filesroot6691c708751e6443App_Web_a3kdfsht.2.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Ok, so here is the solution/hack i came up with. My problem was that adding a user control dynamically (through ajax request) onto page was changing the view state of the page and was throwing an exception. Upon research I found out that viewstate stores the state of a page (properties and settings). Once you return the controls html from a web service, there is going to be some sort of viewstate stored onto page. And when you post back to the server, it will throw an exception when it decrypt the viewstae to rebuild the page. I have simply removed those controls (which got added dynamically) on page post back using jquery and problem got solved.

//In my case "VendorListDropDownSearchable", causes the page post back.
    $("#VendorListDropDownSearchable").change( function () {
        $("#UserControl1DIV").remove(); //removing the place holder holding control1
        $("#UserControl2DIV").remove(); //same as above
    });

Method 2

I know this has been answered but here are a couple of other options:

1). If you’re doing a web service call via jquery .load() you can just remove the viewstate upon return using loads callback parameter

$('#myDiv').load('/MyPage.aspx', null, function(){ 
     $('.aspNetHidden', this).remove(); // removes viewstate from returned aspx html
});

2). Using the Html Agility Pack You can do this same thing in a web service before rendering the returned control. Assume you’re calling a web service which loads a UserControl.ascx in the service and then renders it’s html before returning.
[WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod]
public string GetControlHtml()
{

// do stuff to get the control you want

....

Page page = new Page();
HtmlForm form = new HtmlForm();
var ctl = (MyControlsNameSpace.Controls.MyControl)page.LoadControl("Controls\MyControl.ascx");

page.Controls.Add(form);
form.Controls.Add(ctl);
StringWriter result = new StringWriter();
HttpContext.Current.Server.Execute(page, result, false);

// Extension Method RemoveViewStateFromControl
var MyControlsHTML = result.RemoveViewStateFromControl();
return MyControlsHTML;

}

.....

// In an extensions class....
public static string RemoveViewStateFromExecuteControl(this StringWriter writer)
    {
        HtmlAgilityPack.HtmlDocument Doc = new HtmlDocument();
        Doc.LoadHtml(writer.ToString());
        var Divs = Doc.DocumentNode.SelectNodes("//div");
        if (Divs != null)
        {
            foreach (var Tag in Divs)
            {
                if (Tag.Attributes["class"] != null)
                {
                    if (string.Compare(Tag.Attributes["class"].Value, "aspNetHidden", StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        Tag.Remove();
                    }
                }
            }
        }

        return Doc.DocumentNode.OuterHtml;
    }

Method 3

In my case, the problem was having two <form></form> tags.

I have a TextBox in my main page. If the user enters a value in this TextBox, a Script goes to another page and searches that value while user continues to write it. Normally I created this “another” page by clicking Website, Add New Item. So Visual Studio created a new page for me. As usual there was <form></form> tag in this new page, too. So I deleted this tags and the problem was solved.

Below are my codes:

(PS: I use MasterPage. But the below code is only needed in my main page)

    Dim scriptText As String
    scriptText = ""
    scriptText += "function serinogoster(str) {" + Chr(10)
    scriptText += "var xhttp;" + Chr(10)
    scriptText += "if (str == '') {" + Chr(10)
    scriptText += "document.getElementById('ctl00_ContentPlaceHolder1_Label19').innerHTML = '';" + Chr(10)
    scriptText += "return;" + Chr(10)
    scriptText += "}" + Chr(10)
    scriptText += "xhttp = new XMLHttpRequest();" + Chr(10)
    scriptText += "xhttp.onreadystatechange = function() {" + Chr(10)
    scriptText += "if (this.readyState == 4 && this.status == 200) {" + Chr(10)
    scriptText += "document.getElementById('ctl00_ContentPlaceHolder1_Label19').innerHTML = this.responseText;" + Chr(10)
    scriptText += "}" + Chr(10)
    scriptText += "};" + Chr(10)
    scriptText += "xhttp.open('GET', 'serinover.aspx?serino='+str, true);" + Chr(10)
    scriptText += "xhttp.send();" + Chr(10)
    scriptText += "}" + Chr(10)
    Me.ClientScript.RegisterClientScriptBlock(Me.GetType(), "OnKeyUpScript", scriptText, True)
    TextBox6.Attributes.Add("onkeyup", "serinogoster(this.value);")

In the above code serinover.aspx is the second page which should not have <form></form> tag.

Method 4

Empty the div you loaded “on hiddden”. I found that emptying the div or setting it back to the original text (mine was a loading message) both worked.

<a class="popmodal" href="YOUR HREF HERE" rel="nofollow noreferrer noopener">View History</a>


    $('.popmodal').on('click', function (e) {
                e.preventDefault();
                $('#modalViewBenefitsHistory').modal('show').find('.modal-content').load($(this).attr('href'));
            });


    $('#modalViewBenefitsHistory').on('hidden.bs.modal', function (e) {
                $('.modal-content').empty();
            })

--OR

$('#modalViewBenefitsHistory').on('hidden.bs.modal', function (e) {
            $('.modal-content').text("&nbsp;Loading your benefits history...please wait a moment.");
        })



<div id="modalViewBenefitsHistory" aria-hidden="true" class="modal fade">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            &nbsp;Loading your benefits history...please wait a moment.
        </div>
    </div>
</div>


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x