B
bminder
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
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