Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have a big problem.
My current page have no master page, but my project have master page.
I am loading 3 usercontrols dynamically using webmethod and jquery.

code like this
[WebMethod(EnableSession = true)]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetReviews()
        {
            string content;
            using (Page page = new Page())
            {
                UserControl userControl = (UserControl)page.LoadControl("GetReviewsData.ascx");
                page.Controls.Add(userControl);
                StringWriter sw = new StringWriter();
                HttpContext.Current.Server.Execute(page, sw, true);
                content = sw.ToString();

            }
            return content;
        }

Page is loaded perfectlly. But I have two textboxes and button in a page. When I entered something on textboxes and click button I got error like this.
 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:\Users\Huntable_3\AppData\Local\Temp\Temporary ASP.NET Files\root\dd247138\71070a79\App_Web_jenstl5v.5.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 an illegal character among the padding characters. ]
   System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) +10545468
   System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) +130
   System.Convert.FromBase64String(String s) +41
   System.Web.UI.ObjectStateFormatter.Deserialize(String inputString, Purpose purpose) +66
   System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter2.Deserialize(String serializedState, Purpose purpose) +8
   System.Web.UI.Util.DeserializeWithAssert(IStateFormatter2 formatter, String serializedState, Purpose purpose) +40
   System.Web.UI.HiddenFieldPageStatePersister.Load() +127

[ViewStateException: Invalid viewstate. 
	Client IP: ::1
	Port: 
	Referer: http://localhost:5936/Home.aspx
	Path: /Home.aspx
	User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:30.0) Gecko/20100101 Firefox/30.0
	ViewState: /wEPDwUKLTU0MDM2MDE2OQ9kFgICAQ8WAh4HZW5jdHlwZQUTbXVsdGlwYXJ0L2Zvcm0tZGF0YRYCAiEPFgIeB1Zpc2libGVoZBgB,/wEPDwUBMA9kFgJmD2QWBAIDD2QWBAIBDxYCHgdWaXNpYmxlaGQCAw8WAh8AaGQCBQ8WAh4LXyFJdGVtQ291bnQCBBYIAgEPZBYEAgEPDxYCHghJbWFnZVVybAUbfi9IdW50YWJsZUltYWdlcy9ub21vcmUuanBnZGQCAg8VBBNDYXBnZW1pbmktSm9icy5hc3B4CUNhcGdlbWluaRNDYXBnZW1pbmktSm9icy5hc3B4AzMyNWQCAg9kFgQCAQ8PFgIfAgUbfi9IdW50YWJsZUltYWdlcy9ub21vcmUuanBnZGQCAg8VBBtKb2huc29uLSYtSm9obnNvbi1Kb2JzLmFzcHgRSm9obnNvbiAmIEpvaG5zb24bSm9obnNvbi0mLUpvaG5zb24tSm9icy5hc3B4AzEzNmQCAw9kFgQCAQ8PFgIfAgUbfi9IdW50YWJsZUltYWdlcy9ub21vcmUuanBnZGQCAg8VBA9Ob2tpYS1Kb2JzLmFzcHgFTm9raWEPTm9raWEtSm9icy5hc3B4AzExMGQCBA9kFgQCAQ8PFgIfAgUXfi9Mb2FkRmlsZS5hc2h4P2lkPTE5OTlkZAICDxUEDUNHUy1Kb2JzLmFzcHgDQ0dTDUNHUy1Kb2JzLmFzcHgBMWRkUO+IzCsawxD48EFtlY5TC1dOkyDTdoCnPYBnnCkvda0=BR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAw...]

[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.HiddenFieldPageStatePersister.Load() +266
   System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +88
   System.Web.UI.Page.LoadAllState() +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6704
   System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +245
   System.Web.UI.Page.ProcessRequest() +72
   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
   System.Web.UI.Page.ProcessRequest(HttpContext context) +58
   ASP.home_aspx.ProcessRequest(HttpContext context) in c:\Users\Huntable_3\AppData\Local\Temp\Temporary ASP.NET Files\root\dd247138\71070a79\App_Web_jenstl5v.5.cs:0
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69


Please help me...
Thanks...
Posted
Comments
samit kaneriya 17-Jul-14 1:46am    
The job of a webserivce is not to controls to a page. please find another way for it
NagaRaju Pesarlanka 17-Jul-14 1:49am    
I think webmethod is not a problem.
Thomas Nielsen - getCore 17-Jul-14 6:08am    
looks like you're using webmethods for partial postbacks and i guess some of the modified stuff belongs to the full postback and .net deems it out so to say.
consider not using viewstate at all and simply turn it off if avail
NagaRaju Pesarlanka 17-Jul-14 6:11am    
Thank you for reply me...
I will check it
NagaRaju Pesarlanka 17-Jul-14 6:39am    
I disable and enable in pageload, not working.

1 solution

I understood from your comments that turning ViewState off can work for you, please refer to this on how to do that:
http://msdn.microsoft.com/en-us/library/ms972976.aspx[^]

specifically:
http://msdn.microsoft.com/en-us/library/ms972976.aspx#viewstate_topic9[^]

If not in use ViewState cannot be corrupt of fail and anyway it is a very slow way to persist data between calls as it increases the data going to and from and affects page load times greatly
 
Share this answer
 
Comments
NagaRaju Pesarlanka 18-Jul-14 3:33am    
not a problem, no code in my pageload, I am using jquery.
Thomas Nielsen - getCore 18-Jul-14 3:52am    
ment in the browser :) ViewState as you propably know sends data to and from the browser instead of keeping it at the server and hence the document load in the browser increases when it is in use and it is not a godsent in relation with partial postbacks, such as webmethods
NagaRaju Pesarlanka 18-Jul-14 3:55am    
Is there any alternate without webmethods.
Thomas Nielsen - getCore 18-Jul-14 4:31am    
You could use a webservice, but the essential here is getting rid of the contens of ViewState here, like what you've posted, and in that relation it doesn't matter which way you're getting data
NagaRaju Pesarlanka 19-Jul-14 0:44am    
I want to load usercontols using webservice, Is it better way or not? I got any above viewstate error? Please suggest me, I will try this way.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900