Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Serialized class in web user control loses viewstate on postback

Reply
Thread Tools

Serialized class in web user control loses viewstate on postback

 
 
bminder@gmail.com
Guest
Posts: n/a
 
      04-07-2006
I have a web user control that contains a serializable class. I persist
this class in viewstate, but on postback, the viewstate is null. Is
this behavior by design?

This technique works fine on regular pages -- just not in a control.

Is the main page's viewstate interfering with the control's viewstate?

Thanks,

Brent

Here's a simplified version of the control's code:
--------------------------------------------------
Partial Class WebUserControl
Inherits System.Web.UI.UserControl

<Serializable()> _
Friend Class _ThisPage
Friend _FirstName As String
Friend _LastName As String
End Class
Friend ThisPage As _ThisPage

Public WriteOnly Property LastName() As String
Set(ByVal value As String)
ThisPage._LastName = value
End Set
End Property

Protected Sub Page_Init(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Init
If IsPostBack Then
ThisPage = DirectCast(ViewState("ThisPage"), _ThisPage)
'ViewState("ThisPage") is nothing on postback. Why?
Else
ThisPage = New _ThisPage
End If
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ThisPage._FirstName = "Sandra"
ViewState.Add("ThisPage", ThisPage) 'ViewState("ThisPage")
is valid at this point.
End If
lblName.Text = ThisPage._FirstName & " " & ThisPage._LastName
End Sub
End Class

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
save serialized binary to viewstate question WebBuilder451 ASP .Net 5 11-20-2008 02:14 PM
removing viewstate from serialized state in page? Smokey Grindel ASP .Net 2 12-30-2006 11:17 PM
How to get Serialized string of ViewState Object madani ASP .Net 0 03-04-2006 10:57 AM
HELP: Inherited User Control Loses ViewState Spam Catcher ASP .Net 0 02-18-2006 06:41 AM
How to control the root name with which an array of a custom class objects are serialized???? Bob Rock ASP .Net Web Services 1 06-04-2004 11:28 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57