Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

Error:The state information is invalid for this page and might be corrupted

I am getting this exception on postback from dropdownlist. NOTE: Dropdownlist is bind with BigInt as a value type and its in usercontrol. when i select value in dropdownlist i am getting this exception:

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:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\074f73f4\bcce5747\App_Web_j32tj0nd.0.cs    Line: 0

Stack Trace:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +9594283
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119
   System.Convert.ToInt32(String value, IFormatProvider provider) +48
   System.Web.UI.Page.get_RequestViewStateString() +245

[ViewStateException: Invalid viewstate. 
    Client IP: ::1
    Port: 2479
    Referer: http://localhost:89//home.aspx?catid=8
    Path: /home.aspx
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.18) Gecko/20110614 AskTbPTV2/3.12.2.16749 Firefox/3.6.18 GTB7.1
    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.Page.get_RequestViewStateString() +567
   System.Web.UI.HiddenFieldPageStatePersister.Load() +241
   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.home_aspx.ProcessRequest(HttpContext context) in c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\074f73f4\bcce5747\App_Web_j32tj0nd.0.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

I have done google and tried lots of things like: in webconfig:

<pages maxPageStateFieldLength="40" 

and

 ValidateRequest="false"

but no solution.

Experts please provide me solution. from last few hrs i am facing this issue, earlier it was working fine.

EDIT: NOTE: i have tested now and found that UC is working fine on other pages "TEST PAGE". i think it must be conflicting with some thing... Please suggest..

Upvotes: 0

Views: 9951

Answers (2)

VinayC
VinayC

Reputation: 49195

Your issue is related to page/control life-cycle - when you modify the control tree (or dynamically loads the control), on post-back. ASP.NET expects the same control tree to be present otherwise it cannot load the view-state correctly and gives the error.

So culprit for you is below code:

if (ShowTabbedFlash)
{
   UserControls.TabbedFlash tf = UserControls.TabbedFlash)Page.LoadControl("UserControls/TabbedFlash.ascx");
   Phtabbedflash.Controls.Add(tf);
}

Typically, control tree matching work by matching control ids - by not providing ids, ASP.NET will generate IDs for control - if these gets changed on post-back then ASP.NET run-time encounters incorrect control type for specific id while restoring the view-state and hence the error. Give some specific ID to your user control and it should work (similar logic will apply for any such dynamically loaded controls elsewhere on the page or within user control). For example,

if (ShowTabbedFlash)
{
       UserControls.TabbedFlash tf = UserControls.TabbedFlash)Page.LoadControl("UserControls/TabbedFlash.ascx");
       tf.ID = "SomeUniqueID";
       Phtabbedflash.Controls.Add(tf);
}

Upvotes: 2

Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

Finally i resolved the issue but still i am not able to understand the reason of it.

i resolve the issue like: my page was containing:

My Masterpage contains a property:

 public bool ShowTabbedFlash
        {
            get { return showTabbedFlash; }
            set { showTabbedFlash = value; }
        }

protected void Page_Load(object sender, EventArgs e)
        {
            if (ShowTabbedFlash)
            {
                UserControls.TabbedFlash tf = (UserControls.TabbedFlash)Page.LoadControl("UserControls/TabbedFlash.ascx");
                Phtabbedflash.Controls.Add(tf);
            }
        }

in my Page:

<%@ MasterType VirtualPath="~/Main.Master" %>

in Code i was setting value in property of master page:

private void ShowTabbedFlash()
        {
           Master.ShowTabbedFlash = true;
        }

Now when i have commented code of changing value of masterpage's property

// Master.ShowTabbedFlash = true;

and its started working fine..

Experts please provide me some knowledge that why its happening because of MasterPage's properties?

Upvotes: 0

Related Questions