473,398 Members | 2,335 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.

Accessing ViewState


Hi again,

I'm having a problem accessing the ViewState object. I'm using the following
two functions - as copied from the MS docs - and state.count is zero in the first
- and the while loop in the second function never iterates:

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
public string GetViewStateList ()
{
StateBag state = ViewState;
string result = String.Empty;

if (state.Count > 0)
{
int upperBound = state.Count;
string[] keys = new string[upperBound];
StateItem[] values = new StateItem[upperBound];
state.Keys.CopyTo(keys, 0);
state.Values.CopyTo(values, 0);
StringBuilder options = new StringBuilder();

for(int i = 0; i < upperBound; i++)
{
result = result + "<br>keys:" + keys[i] + "::::values[i].Value:" +
values[i].Value;
}

return result;
}
return "[no count value]";
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
public string EnumerateViewState()
{
Int32 ndx = 0;
string keyName, keyValue;
string result = String.Empty;
StateItem myStateItem;
IDictionaryEnumerator myDictionaryEnumerator = ViewState.GetEnumerator ();

result += "[start]> ";

while(myDictionaryEnumerator.MoveNext())
{
ndx++;
result = result + "[" + ndx.ToString() + "]";
keyName = (string)myDictionaryEnumerator.Key;
myStateItem = (StateItem)myDictionaryEnumerator.Value;
keyValue = (string)myStateItem.Value;
result = result + "<br>ViewState[" + keyName + "] = " + keyValue;
}
return result;
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

Does anyone have any ideas?

THANKS!!!

- wASP
Nov 17 '05 #1
6 13240
Hey dude,
I'm not sure if i'm on the right track with you here, like your trying
to cycle the viewstate for your object. I used to use:

string strUserID = (string)ViewState["UserID"];

in asp.net 1.1 not sure if they're doing it different now. Then i'd do
a check to make sure it wasn't null or empty or something.

Hope this helps,
-Mark

Nov 17 '05 #2
you get to viewstate using viewstate["item"]. The statebag is for backwards
compatibility

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
-------------------------------------------------------------------------------
"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:vu********************************@4ax.com...

Hi again,

I'm having a problem accessing the ViewState object. I'm using the
following
two functions - as copied from the MS docs - and state.count is zero in
the first
- and the while loop in the second function never iterates:

/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
public string GetViewStateList ()
{
StateBag state = ViewState;
string result = String.Empty;

if (state.Count > 0)
{
int upperBound = state.Count;
string[] keys = new string[upperBound];
StateItem[] values = new StateItem[upperBound];
state.Keys.CopyTo(keys, 0);
state.Values.CopyTo(values, 0);
StringBuilder options = new StringBuilder();

for(int i = 0; i < upperBound; i++)
{
result = result + "<br>keys:" + keys[i] + "::::values[i].Value:"
+
values[i].Value;
}

return result;
}
return "[no count value]";
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */
public string EnumerateViewState()
{
Int32 ndx = 0;
string keyName, keyValue;
string result = String.Empty;
StateItem myStateItem;
IDictionaryEnumerator myDictionaryEnumerator = ViewState.GetEnumerator
();

result += "[start]> ";

while(myDictionaryEnumerator.MoveNext())
{
ndx++;
result = result + "[" + ndx.ToString() + "]";
keyName = (string)myDictionaryEnumerator.Key;
myStateItem = (StateItem)myDictionaryEnumerator.Value;
keyValue = (string)myStateItem.Value;
result = result + "<br>ViewState[" + keyName + "] = " + keyValue;
}
return result;
}
/* ------------------------------------------------------------------ */
/* ------------------------------------------------------------------ */

Does anyone have any ideas?

THANKS!!!

- wASP

Nov 17 '05 #3
On 2 Aug 2005 02:53:16 -0700, sh**********@gmail.com wrote:
Hey dude,
I'm not sure if i'm on the right track with you here, like your trying
to cycle the viewstate for your object. I used to use:

string strUserID = (string)ViewState["UserID"];

in asp.net 1.1 not sure if they're doing it different now. Then i'd do
a check to make sure it wasn't null or empty or something.

Hope this helps,
-Mark


Hi Shadow Demon,

Thanks for the response, but it doesn't really address my issue.

I need to be able to iterate through all entries to the ViewState.

Apparently, noone has any idea as to what the problem is.

Thanks again,

- wASP
Nov 17 '05 #4
On Tue, 2 Aug 2005 13:13:47 -0400, "Alvin Bruney [Microsoft MVP]" <www.lulu.com/owc>
wrote:
you get to viewstate using viewstate["item"]. The statebag is for backwards
compatibility


Thanks Alvin,

So how would I get an array of strings that enumerates all
of the available/valid indicies within the viewstate object?

- wASP
Nov 17 '05 #5
you can't. if you need this for reporting, just turn on tracing and
viewstate will be dumped on the page. tracing internally enumerates the
viewstate object. i'm not aware of a way to enumerate the viewstate object
otherwise.

--
Regards
Alvin Bruney
[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
available at www.lulu.com/owc, Amazon, B&H etc
-------------------------------------------------------------------------------
"wASP" <wylbur[at]ev1[dot]net> wrote in message
news:ma********************************@4ax.com...
On Tue, 2 Aug 2005 13:13:47 -0400, "Alvin Bruney [Microsoft MVP]"
<www.lulu.com/owc>
wrote:
you get to viewstate using viewstate["item"]. The statebag is for
backwards
compatibility


Thanks Alvin,

So how would I get an array of strings that enumerates all
of the available/valid indicies within the viewstate object?

- wASP

Nov 17 '05 #6
On Wed, 3 Aug 2005 22:56:41 -0400, "Alvin Bruney [Microsoft MVP]" <www.lulu.com/owc>
wrote:
you can't. if you need this for reporting, just turn on tracing and
viewstate will be dumped on the page. tracing internally enumerates the
viewstate object. i'm not aware of a way to enumerate the viewstate object
otherwise.


Ahhh - I guess that explains why I can't do it then.

THANKS Alvin!

- wASP
Nov 17 '05 #7

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

Similar topics

1
by: | last post by:
Is it possible to access the previous page's viewstate directly through the context object after a server.transfer. If so, how? The way i'm doing it is saving all needed items to a structure on...
11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
3
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
8
by: Jeronimo Bertran | last post by:
I have an aspx page that saves some information using the ViewState. This page has an IMG META that uses a second aspx page to render the image. <IMG src= "ImageRender.aspx"> I noticed that...
3
by: Jordan | last post by:
My ASP.NET 1.1. app dynamically loads a user control into a PlaceHolder control that exists in an aspx page. The user control is loaded during the Page_Load event of the aspx. The PlaceHolder's...
3
by: =?Utf-8?B?TmF2bml0?= | last post by:
Hi, I have the following scenario:- 1) I have a web part 2) This web part uses a class library 3) In the Class Library I want to save and retrieve values from the ViewState I am not able to...
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
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.