Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Don't preserve viewstate when doing a Server.Transfer

Total Hit ( 2990)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


The ASP.NET version of the Server.Transfer method accepts a second argument which, if true, causes the query string and all the form's fields to be transferred and made available to the destination page. However, when the destination page executes, the following error is likely to be generated:

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

The reason for this error is that the EnableViewStateMac attribute of the element of Web.config is set to true by default. This causes a message authentication check (MAC) on the view state of the page being posted back. The view state is held in the __VIEWSTATE hidden field, and the MAC fails because the MAC only checks each page. In other words, the view state of the page where Server.Transfer is called isn't valid on the destination page. This problem is discussed more estensively on the KB article mentioned at the bottom of this page.
You avoid this problem by not passing True as the second argument of the Server.Transfer method. However, you must devise alternative ways to make the query string and controls' values of the source page available to the destination page, if these values must be processed by the destination page. There are two ways to achive this. The easiest way is to make all controls on the source page public, as in:

Click here to copy the following block
Public Class WebForm1
  Public WithEvents txtUserName As System.Web.UI.WebControls.TextBox
  ' ...
End Class

A safer way is to wrap these control's values in properties:
Public Class WebForm1
  Private WithEvents txtUserName As System.Web.UI.WebControls.TextBox
  ' ...

  ReadOnly Property UserName() As String
    Get
      Return Me.txtUserName.Text
    End Get
  End Property
End Class

In both cases you can then access the actual value from the destination page as follows:

Click here to copy the following block
' inside the destination page
Dim sourcePage As WebPage1 = DirectCast(Context.Handler, WebForm1)
Dim userName As String = sourcePage.UserName

For more information see: MSKB Article Q316920.



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.