Click here to Skip to main content
Click here to Skip to main content

Tagged as

ViewState and Server.Transfer Best practices

, 20 Apr 2010
Rate this:
Please Sign up or sign in to vote.
ViewState and Server.Transfer Best practicesScenario : Server.Transfer("destiny.aspx",true); Above statement will cause ViewState is invalid exceptionReason :By default EnableViewStateMac is set to true, and hence on every page life cycle , it tries to validate the value of the...
ViewState and Server.Transfer Best practices
 
Scenario :
 
 Server.Transfer("destiny.aspx",true); 
Above statement will cause ViewState is invalid exception
 
Reason :
 
By default EnableViewStateMac is set to true, and hence on every page life cycle , it tries to validate the value of the ViewState(for security reason) ,which is a part of forms collection(__ViewState - hidden field) and by ViewState design at any given point you can post to only one form...Hence in the prior case , it tries to compare the ViewState of the source with the destiny and hence the above mismatch happens Smile | :)
 
Best practices to Transfer the control to the other page without affecting the view state
 
Option 1
 
use
 
Server.Transfer("destiny.aspx",false);
 
- The Second parameter in the above statement is set to false , Hence it is not preserving the prvious page folrms collections..
 
Option 2
 
Passing Server control value between pages
 
http://msdn2.microsoft.com/en-us/library/6c3yckfw(vs.71).aspx
 

 
I hope this helps!.
 
Regards,
-Vinayak

License

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

Share

About the Author

Vinayaka Krishna Shenoy
Architect MindTree Ltd
India India
Motivated achiever who guides organizations in applying technology to business settings, provides added value, and creates project deliverables in a timely manner. An experienced Technical Consultant, have successfully led large project teams of more than 20 people from requirements gathering to implementation and support using C#, .NET ,ADO.NET, ADO.NET Entity Framework,ASP.NET,ASP.NET MVC, WCF and SQL Server.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 21 Apr 2010
Article Copyright 2010 by Vinayaka Krishna Shenoy
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid