ViewState Collection in ASP.Net

  • Thread starter Thread starter SouthSpawn
  • Start date Start date
S

SouthSpawn

Hello,

Let's say I am creating a class library project.
This class that I am creating will work for a windows form project and
also a asp.net project.

How can I store something in the "ViewState" collection in a class
library
project?

Thanks,
Mark
 
I'm just curious. You say it will work on Windows Forms and Web Forms
projects. Windows Forms applications don't have ViewState. How you are
planning to go around this?
 
Hi Stoitchom,

I was going to create a public property.
The calling class will let the object know if it's a web form app or a
windows form app.

Basically, I just need to know how I can set the viewstate object in a
class library.
 
SouthSpawn,

Basically you can't, The ViewState is a property of the
System.Web.UI.Control, unless you inherit from this type you don't have a
view state.
Ofcourse there is a workaround. In your page class you can decalre one
public property that exposes the view state of the page. Then your class can
do something like
((MyPage)System.Web.HttpContext.Current.Handler)MyPublicViewState.

Anyways I'm not exactly sure that it is a good idea an object to save its
data to somebody else's view state. The view state is per control and is the
control's private storage. I belive if one control wants to share its view
state then the control needs to initiate this; to show goodwill so to speak.
This sneeking and using somebody else's resources I personally don't like.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top