views:

67

answers:

3

Let's say you have a page that produces text/plain output. If you set the ViewState in Page_Load, it doesn't do anything to the output (which makes sense).

My question is, does text/plain turn off ViewState processing? What does ASP.NET do to decide when it'll turn things off?

+1  A: 

In order to have a view state enabled you must have <form runat="server"> element in your ASP.Net. Since you are using plain text as output you probably don't have this element.

boredgeek
If you don't have that element, half of controls will complain and throw an error.
Ruslan
These controls are not very useful with text/plain anyway. I guess in this case the other half is used.
boredgeek
A: 

How exactly are you producing the plain text output? Do you clear response, use Response.Write and .End on Load or do custom rendering? In this case you decide the ViewState's fate. Do you simply set Response.ContentType = "text/plain"? Then you still have your ViewState, but a browser displays it as a plain text. And finally, why should setting the ViewState do anything to the output in the first place (other than modifying the hidden field)?

Ruslan
A: 

For this kind of output I'd suggest using a generic handler (.ashx) since it is simpler and lighter.

Andrei Rinea