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

When we use server.transfer method to navigate to next page, at times we give value; as the second parameter for the method. In this cases we tend to get the error message

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

This is because the view state of the page where Server.Transfer is called isn't valid on the destination page.

To avoid this problem  do not pass “True” as the second parameter for the Server.Transfer method. An easy and safer way to make the values of the source page available to the destination page, is to wrap these control's values in properties:
Public Class WebForm1

Private WithEvents txtloginID As System.Web.UI.WebControls.TextBox
   ' ...

    ReadOnly Property LoginID() As String
            Return Me.txtloginID.Text
        End Get
    End Property
End Class

Inside the destination page you can access the values of the source page as

Dim source As WebPage1 = DirectCast(Context.Handler, WebForm1)
Dim loginID As String = source.loginID.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.