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

Trying to store items in the viewstate... wont work

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.

I am trying to navigate through 4 stages of my script and saving data as i
go along. Typically i would use hidden variables however as there are no
server controls for these built in, i presumed they shouldnt be used as I
have no way of setting there values programatically (i dont think anyway).

I have a custom user control, within it at some point i execute the
following:

ViewState.Add("temp", "testing");

Then within my main page the following returns null pointer errors:

string test2 = ViewState["temp"].toString();

I have tried loading the viewstate after the page is rendered (i.e. set the
viewstate, render the page, click a button and see if my data is saved when
it rendered again [refreshing the view state]). Again doesnt work, same
problem.

I would really appreciate a simple way of doing this that would
automatically flush the data once the user has left the page. i.e. caching
or sessions arent really what I am looking for.

Thanks for any help.
Taz
Feb 13 '06 #1
5 1337
Update:

If i move the ViewState.Add("temp", "testing"); line into my main page,
everything now works. Why isnt the view state set from within the
usercontrol? :S

Thanks everyone,
Taz

Feb 13 '06 #2
Dumb question:
Is ViewState of the control enabled?
Did you try to use Page.ViewState instead of using the ViewState property
that belongs to the control?

"Tarun Mistry" <no****@nospam.com> wrote in message
news:ec*************@TK2MSFTNGP09.phx.gbl...
Update:

If i move the ViewState.Add("temp", "testing"); line into my main page,
everything now works. Why isnt the view state set from within the
usercontrol? :S

Thanks everyone,
Taz

Feb 13 '06 #3
> Did you try to use Page.ViewState instead of using the ViewState property
that belongs to the control?


Hmm i was under the impression the ViewState was global across the entire
page and its contents. I will definately look into this!

Thank you.

Kind regards
Taz
Feb 13 '06 #4
Well, I'm not really sure about that, but I think you should try!
Did it work?
"Tarun Mistry" <no****@nospam.com> wrote in message
news:uz*************@TK2MSFTNGP15.phx.gbl...
Did you try to use Page.ViewState instead of using the ViewState property
that belongs to the control?


Hmm i was under the impression the ViewState was global across the entire
page and its contents. I will definately look into this!

Thank you.

Kind regards
Taz

Feb 14 '06 #5
Appologies for the late reply, it did not work.

The ViewState is only available on the main page, not the custom user
controls, so you need to raise events and create custom properties to send
data back to the main page.

Kind regards
Taz

"Ravi Ambros Wallau" <no****@nospam.com> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
Well, I'm not really sure about that, but I think you should try!
Did it work?
"Tarun Mistry" <no****@nospam.com> wrote in message
news:uz*************@TK2MSFTNGP15.phx.gbl...
Did you try to use Page.ViewState instead of using the ViewState
property that belongs to the control?


Hmm i was under the impression the ViewState was global across the entire
page and its contents. I will definately look into this!

Thank you.

Kind regards
Taz


Feb 25 '06 #6

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

Similar topics

3
by: Stephen | last post by:
I've got a datagrid with a remove button and I would like to add some code in the code behind page so as whenthe button is clicked the corresponding row in the datagrid is removed. The Datagrid is...
4
by: Stephen | last post by:
I have got an event below to remove items from an arraylist and then to rebind the arraylist to the datagrid subsequently deleting the appropriate row. My problem is that my code makes sense and 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...
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...
2
by: Andrew | last post by:
I hope this doesn't sound too silly. I am trying to cache a datatSet. I have written the code below. I insert into the cache: Eg. i = 1. if (Cache == null) { Cache.Insert("testQuestion"+ i,...
12
by: TB | last post by:
Hi All: I am trying to create a variation on the standard datagrid, whereby the datagrid is only shown after pressing some buttons. This reason for this is that I would like to use the same...
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...
2
by: Bart Van Hemelen | last post by:
The situation: I have a CheckBoxList cblTest, the items are disabled in cblTest_DataBound in a foreach (ListItem oItem in cblTest.Items) loop. I provide a link that calls a client-side JavaScript...
1
by: robert112 | last post by:
Hi All, I have a webpage.aspx and a webusercontrol.ascx with both of them having viewstate turned off. Then in my web user control I have got some code reading the request stream: Dim str As...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...

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.