473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Serialized class in web user control loses viewstate on postback

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

Apr 7 '06 #1
0 1391

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Guadala Harry | last post by:
I have a simple user control (see below) that has EnableViewState="true". I place it on an ASPX page at runtime using a PlaceHolder - which also has EnableViewState="true". After a postback, the...
2
by: Sam Kuehn | last post by:
There has been a lot of articles on how to load user controls at runtime in the Init() method. UserControl myControl = (UserControl)LoadControl(stringControl); I add the control in the Init()...
5
by: Steve Richter | last post by:
In my user control I want to read the ViewState dictionary of the Parent control. But this sensible idea is not permitted by the compiler: Compiler Error Message: CS1540: Cannot access...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
1
by: Ken Varn | last post by:
I have a problem where my DataGrid would not maintain the ViewState of my databound rows. I finally narrowed down the problem. If my first column is a template column, the view state for the...
5
by: serge calderara | last post by:
Dear all, I try to study Web user control .For that I have created a simple text box with button as a webuser control which has 2 properties. Then I drop my user control on a web page for...
0
by: John Smith | last post by:
I still have not gotten this damn thing figured out and I'm asking for help one last time before I give up on it. I have a user control that contains a paged gridview control. The master page...
0
by: xpnet | last post by:
Hi, I am using Mutliview control, and want to move a user control from one view to another view based on user selection. I can do this by placing a "Placeholder" control in each views. Based on...
5
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I can very simple save a serilized class to a server, but i don't know how to serilize an object (here a business object) to a variable so that it can be saved to viewstate or passed to another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.