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