Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tarun Mistry - 13 Feb 2006 19:36 GMT
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
Tarun Mistry - 13 Feb 2006 19:56 GMT
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
Ravi Ambros Wallau - 13 Feb 2006 20:11 GMT
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?

> Update:
>
[quoted text clipped - 4 lines]
> Thanks everyone,
> Taz
Tarun Mistry - 13 Feb 2006 23:11 GMT
> 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
Ravi Ambros Wallau - 14 Feb 2006 15:54 GMT
Well, I'm not really sure about that, but I think you should try!
Did it work?
>> Did you try to use Page.ViewState instead of using the ViewState property
>> that belongs to the control?
[quoted text clipped - 6 lines]
> Kind regards
> Taz
Tarun Mistry - 25 Feb 2006 10:08 GMT
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

> Well, I'm not really sure about that, but I think you should try!
> Did it work?
[quoted text clipped - 8 lines]
>> Kind regards
>> Taz

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.