Reputation: 612
I'm working on a Asp.net project where I have created some user controls on page dynamically through LoadControl() on Page Object but when I try to do any postback through any page I get "The state information is invalid for this page and might be corrupted."
even when I have set Viewstate of dynamically created control to false.
If you have faced this problem please tell me how you fixed it.
The stack trace is:-
[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.
[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) +198
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.contact_us_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\otherland_ecom\33f31476\6c5f9007\App_Web_zgmfrrfa.14.cs:0
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Upvotes: 5
Views: 22516
Reputation: 898
I've swapped Viestate storage for Session and this issue disappeared. When Session expires my login expires so the page is forced to reload and stay valid:
//ViewState["startConversion"] = false;
Session["startConversion"] = false;
Or
<asp:HiddenField ID="hfStartConversion" runat="server" />
Upvotes: -1
Reputation: 3700
I think u have added the control after page_load method. when you add control it add the hidden field which is try to mach it when page post back it does not mach with the initial hidden field so it rise the error to when you add control dynamically try to remove its hidden field then it will solve your problem.
Upvotes: 0
Reputation: 1347
Set EnableEventValidation to false in design page(.aspx)
<%@ Page Title="Home Page" EnableEventValidation="false" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
Upvotes: 1
Reputation: 8337
Can you please make sure that the dynamic controls are loaded before Page_Load. You can load them in Page_Init. (No need to assign values as they will be assigned from the viewstate).
Upvotes: 1