Thursday, October 13, 2005

The View State is invalid for this page and might be corrupted

This error occured when i use Server.Transfer. It seems that the ViewState security has been set higher. There are two ways to overcome it.

First, by using response.redirect rather than server.transfer. However, response.redirect doesn't save the page state. There are ways to do so. One of it is by using session. Another is by integrate it into the URL string.

IF the first method doesn't satify you, there is another way. This method is shown in Microsoft's support website.

Code in page1.aspx
Public Class Page1
Public WithEvents TextBox1 As System.Web.UI.WebControls.TextBox

'Insert your code here.
End Class

Code in page2.aspx
Dim sourcePage As Page1
sourcePage = CType(Context.Handler, WebForm1)

There's another method(which makes up 3 method~!) to overcome the error above,


*But this method ignore's the page state. In other words, you can't pass the data to second page.

Reference: Microsoft's Support

Your Ad Here