473,396 Members | 1,734 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,396 software developers and data experts.

Class That use ViewState/session

Max
I need an vb.net class that is invoked from aspx page, that use the
viewstate/session object.
This class must be store the information into viewstate/session.

Can you give me an example ?
Thanks
Nov 21 '05 #1
6 1528
You can do it so that Page calls a method of the class, which returns
something which is again placed into ViewState or Session by the Page. This
way class doesn't need to know about the ViewState collection like the key
used and so on, which is actually better for many reasons

-no chance for name collisions
-class library is usable from other type projects than web projects (Windows
Forms, or WinServices...)
-class does only it's job, no extra reponsibilities
-clear workings for the class consumer

'Code on the Page
Dim cIns As New TheClassInstance()
ViewState("data") = cIns.returnSomething()

'Then again getting it back
....

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
I need an vb.net class that is invoked from aspx page, that use the
viewstate/session object.
This class must be store the information into viewstate/session.

Can you give me an example ?
Thanks

Nov 21 '05 #2
On Thu, 24 Mar 2005 19:19:12 +0100, "Max" <ma*******@hotmail.com>
wrote:
I need an vb.net class that is invoked from aspx page, that use the
viewstate/session object.
This class must be store the information into viewstate/session.

Can you give me an example ?
Thanks


The easiest way would be to pass the ViewState from you Page class.
Here is an example (sorry if the syntax is a bit wrong, I am not
really a VB guy):
In Page code:
....
'Create an instance of custom class
Dim objMyClass As MyClass
Set objMyClass = New MyClass( Me.ViewState )
....

In class code:
....
Private viewState As System.Web.UI.StateBag

Public New( ByRef pageViewState As System.Web.UI.StateBag )
Set viewState = pageViewState
End
....
Nov 21 '05 #3
Max
hi,
from aspx page, i instance an class.
in an method of this class, i need insert into viewstate a data.
can i reference from class to viewstate of the page that have instance the
class ?
Thanks
"Teemu Keiski" <jo****@aspalliance.com> ha scritto nel messaggio
news:OG**************@TK2MSFTNGP12.phx.gbl...
You can do it so that Page calls a method of the class, which returns
something which is again placed into ViewState or Session by the Page.
This way class doesn't need to know about the ViewState collection like
the key used and so on, which is actually better for many reasons

-no chance for name collisions
-class library is usable from other type projects than web projects
(Windows Forms, or WinServices...)
-class does only it's job, no extra reponsibilities
-clear workings for the class consumer

'Code on the Page
Dim cIns As New TheClassInstance()
ViewState("data") = cIns.returnSomething()

'Then again getting it back
...

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
I need an vb.net class that is invoked from aspx page, that use the
viewstate/session object.
This class must be store the information into viewstate/session.

Can you give me an example ?
Thanks


Nov 21 '05 #4
Hi,

As is described on following reply, yes you can, but it's not that good
approach. However, if you just want it done and don't care about what else
it might mean, then sure you can just pass the ViewState collection from the
Page to the class and use it (just pay attention to the drawbacks I
mentioned)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
hi,
from aspx page, i instance an class.
in an method of this class, i need insert into viewstate a data.
can i reference from class to viewstate of the page that have instance the
class ?
Thanks
"Teemu Keiski" <jo****@aspalliance.com> ha scritto nel messaggio
news:OG**************@TK2MSFTNGP12.phx.gbl...
You can do it so that Page calls a method of the class, which returns
something which is again placed into ViewState or Session by the Page.
This way class doesn't need to know about the ViewState collection like
the key used and so on, which is actually better for many reasons

-no chance for name collisions
-class library is usable from other type projects than web projects
(Windows Forms, or WinServices...)
-class does only it's job, no extra reponsibilities
-clear workings for the class consumer

'Code on the Page
Dim cIns As New TheClassInstance()
ViewState("data") = cIns.returnSomething()

'Then again getting it back
...

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
I need an vb.net class that is invoked from aspx page, that use the
viewstate/session object.
This class must be store the information into viewstate/session.

Can you give me an example ?
Thanks



Nov 21 '05 #5
Max
thanks,
but it necessary to pass the viewstate reference from aspx page to class ?
it's no possibile that class use viewstate without pass it from aspx page ?
thanks

"Teemu Keiski" <jo****@aspalliance.com> ha scritto nel messaggio
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

As is described on following reply, yes you can, but it's not that good
approach. However, if you just want it done and don't care about what else
it might mean, then sure you can just pass the ViewState collection from
the Page to the class and use it (just pay attention to the drawbacks I
mentioned)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
hi,
from aspx page, i instance an class.
in an method of this class, i need insert into viewstate a data.
can i reference from class to viewstate of the page that have instance
the class ?
Thanks
"Teemu Keiski" <jo****@aspalliance.com> ha scritto nel messaggio
news:OG**************@TK2MSFTNGP12.phx.gbl...
You can do it so that Page calls a method of the class, which returns
something which is again placed into ViewState or Session by the Page.
This way class doesn't need to know about the ViewState collection like
the key used and so on, which is actually better for many reasons

-no chance for name collisions
-class library is usable from other type projects than web projects
(Windows Forms, or WinServices...)
-class does only it's job, no extra reponsibilities
-clear workings for the class consumer

'Code on the Page
Dim cIns As New TheClassInstance()
ViewState("data") = cIns.returnSomething()

'Then again getting it back
...

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
I need an vb.net class that is invoked from aspx page, that use the
viewstate/session object.
This class must be store the information into viewstate/session.

Can you give me an example ?
Thanks



Nov 21 '05 #6
If your class would be a control, it would have its own ViewState collection
(which would be saved and restored by the page framework).

However, if your class is stand-alone custom class, it either can take the
ViewState collection as a reference in and operate with it, or it can just
return the value(s) to the caller (Page) and let that handle operating with
the ViewState (there are examples of both in this thread).

Only controls (Page and its controls) have ViewState collection (each
control has its own) and therefore accessing it from a custom class needs
certain approach. Sessions you could access from class via
System.Web.HttpContext.Current.Session, but there's not similar way to
access ViewState.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
thanks,
but it necessary to pass the viewstate reference from aspx page to class ?
it's no possibile that class use viewstate without pass it from aspx page
?
thanks

"Teemu Keiski" <jo****@aspalliance.com> ha scritto nel messaggio
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

As is described on following reply, yes you can, but it's not that good
approach. However, if you just want it done and don't care about what
else it might mean, then sure you can just pass the ViewState collection
from the Page to the class and use it (just pay attention to the
drawbacks I mentioned)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
hi,
from aspx page, i instance an class.
in an method of this class, i need insert into viewstate a data.
can i reference from class to viewstate of the page that have instance
the class ?
Thanks
"Teemu Keiski" <jo****@aspalliance.com> ha scritto nel messaggio
news:OG**************@TK2MSFTNGP12.phx.gbl...
You can do it so that Page calls a method of the class, which returns
something which is again placed into ViewState or Session by the Page.
This way class doesn't need to know about the ViewState collection like
the key used and so on, which is actually better for many reasons

-no chance for name collisions
-class library is usable from other type projects than web projects
(Windows Forms, or WinServices...)
-class does only it's job, no extra reponsibilities
-clear workings for the class consumer

'Code on the Page
Dim cIns As New TheClassInstance()
ViewState("data") = cIns.returnSomething()

'Then again getting it back
...

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU

"Max" <ma*******@hotmail.com> wrote in message
news:3a*************@individual.net...
>I need an vb.net class that is invoked from aspx page, that use the
>viewstate/session object.
> This class must be store the information into viewstate/session.
>
> Can you give me an example ?
> Thanks
>



Nov 21 '05 #7

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

Similar topics

4
by: Free | last post by:
Hi, I have a question about ASP.NET : Here is an example of WebForm code. 2 buttons and 1 textbox. ----------------------------------------------------------------------------...
10
by: neo | last post by:
hi, I am studying ASP.NET and have few questions - 1) The session ID and values of controls is stored in VIEWSTATE variable. So now when we put EnableViewState="false" in Page directive and...
6
by: clsmith66 | last post by:
Is it possible to store the same information about a control that would be saved in the ViewState in a Session state? I have a page with three treeview controls and if I enable the view state for...
6
by: Max | last post by:
I need an vb.net class that is invoked from aspx page, that use the viewstate/session object. This class must be store the information into viewstate/session. Can you give me an example ? Thanks
7
by: fisab | last post by:
I apologise in advance for such a basic question, but I'm hoping someone will take the time to answer my question. In my code I define a Dataset : Partial Class Default_aspx Dim dsExcel As...
3
by: RCS | last post by:
I have an app that I have different "sections" that I want to switch back and forth from, all while having the server maintain viewstate for each page. In other words, when I am on Page1.aspx and...
7
by: Ben Amada | last post by:
I've created a class that I need to store in ViewState. However when I try to store it in ViewState, I get the following error: "The type 'solution.pe2' must be marked as Serializable or have a...
15
by: Joe Fallon | last post by:
I would like to know how you can figure out how much memory a given instance of a class is using. For example, if I load a collection class with 10 items it might use 1KB, and if I load it with...
6
by: mosscliffe | last post by:
I am testing for how/when a page is posted back and I decided to use a ViewState variable in PageLoad to set up a counter, but it appears, the ViewState is cleared on each PageLoad. So then I used...
3
by: Trust Me; I'm from the government | last post by:
I have an employee class - in my page, when it loads, it gets all the employee data, including the employee Number. I have Dim emp As New Employee (at the top of the page, so it's global to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.