473,387 Members | 1,582 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,387 software developers and data experts.

How to store a structure in ViewState

Hi, I have a structure that I need to save between pages. Can not use
sessions. I would love to use ViewState, but, I get this error!

The type 'TicketSystemV2.ucTicketList+OrderBy' must be marked as
Serializable or have a TypeConverter other than ReferenceConverter to be put
in viewstate.
Here is my code:

Public Structure OrderBy
Public DateSort As Boolean
Public SortDir As String
Public SeveritySort As Boolean
Public AssignedToSort As Boolean
Public OfficeSort As Boolean
Public ProblemSort As Boolean
Public TimeSort As Boolean
End Structure

In the page load:

Dim pOrderBy As New OrderBy()

pOrderBy.DateSort = True
pOrderBy.SortDir = "D"
pOrderBy.SeveritySort = False
pOrderBy.AssignedToSort = False
pOrderBy.OfficeSort = False
pOrderBy.ProblemSort = False
pOrderBy.TimeSort = False

ViewState.Add("bla", pOrderBy)
The error message happens once all the code has been executed and the page
is acutally loading.

Any ideas?
Nov 18 '05 #1
2 4746
Viewstate doesn't support holding objects like that, at least not that
easily. If you want to keep the solution simple, make two functions. The
first one takes in this structure as a parameter, and returns a string (a
string which somehow contains enough info about the structure to recreate
it) For example "t;mysordir;t;f;t;f;f". Store that string to the
viewstate. In your second method, take in this string (which you retrieve
from the viewstate), do whatever you need to recreate the structure, and
return the structure.

Sounds good to me anyway :-)
--Michael
Nov 18 '05 #2
yea.... I had that idea too.

looks like thats the way to go.....
Thanks for the help.

George

"Raterus" <raterus@localhost> wrote in message
news:e2***************@tk2msftngp13.phx.gbl...
Viewstate doesn't support holding objects like that, at least not that
easily. If you want to keep the solution simple, make two functions. The
first one takes in this structure as a parameter, and returns a string (a
string which somehow contains enough info about the structure to recreate
it) For example "t;mysordir;t;f;t;f;f". Store that string to the
viewstate. In your second method, take in this string (which you retrieve
from the viewstate), do whatever you need to recreate the structure, and
return the structure.

Sounds good to me anyway :-)
--Michael

Nov 18 '05 #3

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

Similar topics

0
by: wASP | last post by:
I thought it was something relatively simple: ViewState = SomeObj; Then: SomeObj = ViewState; So, in my own code, I have this on the initial load:
3
by: Martin | last post by:
Dear fellow ASP.NET programmer, I stared using forms authentication and temporarily used a <credentials> tag in web.config. After I got it working I realized this wasn't really practical. I...
5
by: Joakim Westman \(Elicit AB\) | last post by:
Hi! I have a page that generates a lot of HTML, and I am considering different solutions to constrain the amount of code that is sent back to the client. One thing I thought about is the...
2
by: Sky | last post by:
Basically, I'm stumped on how to translate something I wrote in PHP to ASP.NET, and I'm having a hard time figuring out what is right way to do it now... The scenario in PHP was as follows: I...
0
by: Patrick Delifer | last post by:
Hi, can anyone tell me how to store my Datagrid list in a viewstate? (or where I can get such info , I looked everywhere with no luck) This is not for sorting. The problem I'm having is the...
1
by: Pipo | last post by:
Hi, I'm trying to store a delegate into a viewstate but I get the message that it needs to be serialized then. So I put the attribute <Serializable> in the delegate..but this isnt enough... ...
4
by: Robert P. | last post by:
I can easily store a one-dimensional array in viewstate ( see Test1 ) If I try storing a multi-dimensional array in the viewstate it's crapping out on me when it goes to serialize the array (not...
5
by: Tarun Mistry | last post by:
Hi all, im attempting to use the ViewState instead of the hidden values normally used in procedural web development, however i cant seem to get anything to add into it or load correctly from it. ...
7
by: Shadow Lynx | last post by:
I realize that his question has been asked, in many other forms, many times in this group. Even so, my tired eyes have not yet found a sufficient answer, so I've decided to "reask" it even though...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...

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.