What does the __VIEWSTATE hold?
Asked Answered
O

6

17

I'm sorry for maybe making such a basic question but in ASP.NET websites what does the __VIEWSTATE input field represent?

Also, is there any way to compute it's value (based on the values of other form fields)?

EDIT

I understand that __VIEWSTATE, as the name suggests, maintains the values of form field values in webpages however what I'm interested in knowing is how this state (the string) is generated. If I base64_decode any __VIEWSTATE string all I see is a bunch of cryptic HTML.

Is there any way to better understand what exactly is being encoded? I've searched on past questions and I've found some tools that can do this like this one, but unfortunately it doesn't seem to work.

The reason I'm asking this is because I've access to a web service API that gives me most of the values I need to work with. However I also need an additional field that is only available on the last stage of the form. I already contacted the web service provider but unfortunately and they're not going to update their API so soon. I was hoping I could prefill the form initial values using the web service data and then calculate the __VIEWSTATE to access the last field that shows up on the last stage of the form, it would make the whole process a lot faster.

Not sure if I made myself clear enough though...

Oneill answered 29/8, 2009 at 2:6 Comment(1)
Answers to this question is a list of links :/Celaeno
G
8

Paul Wilson has a very good article: ViewState: All You Wanted to Know

VIEWSTATE can be deserialized with the LosFormatter class.

Gilded answered 29/8, 2009 at 2:59 Comment(0)
C
1

A quick Google search answers the question:

http://msdn.microsoft.com/en-us/library/ms972976.aspx

First sentence:

Microsoft® ASP.NET view state, in a nutshell, is the technique used by an ASP.NET Web page to persist changes to the state of a Web Form across postbacks.

Cowslip answered 29/8, 2009 at 2:9 Comment(4)
Search google? Communist! 90% of this site would go away if people started doing that. :)Retractor
+1, and it was funny, because it's true... (read it imitating Sheldon Cooper's voice)Barris
@John Lockwood and @Cowslip 1 plus for both of youPythagorean
The funny thing is 90% of SO's traffic comes from Google. I think Jeff Atwood mentioned it in one of the podcasts.Sverre
L
1

If you really want to understand it well, see Dave Reed's article about ViewState.

Lavernalaverne answered 29/8, 2009 at 2:49 Comment(0)
E
1

Do take a look at the biter script posted at http://forums.techarena.in/windows-software/1329157.htm.

That script shows how to set up and use __ViewState and other .NET variables.

That script logs into a .NET site, and gets stock values, without going thru a browser. Instead of user doing it manually, the script does it programmatically.

Exhaust answered 20/8, 2010 at 18:33 Comment(0)
M
0

What do you mean by compute it's value?

Assume that it is a compressed (actually Base64 encoded) pair of your form fields/values in text form, which gets serialized into server side objects for you to work with.

Merell answered 29/8, 2009 at 2:10 Comment(0)
J
0

The easiest way of doing this in Razor is putting this on a view:

@{
    throw new Exception();
} 
Johns answered 18/12, 2017 at 1:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.