473,839 Members | 1,399 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1546
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 TheClassInstanc e()
ViewState("data ") = cIns.returnSome thing()

'Then again getting it back
....

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

"Max" <ma*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.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*******@hotm ail.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.S tateBag

Public New( ByRef pageViewState As System.Web.UI.S tateBag )
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****@aspalli ance.com> ha scritto nel messaggio
news:OG******** ******@TK2MSFTN GP12.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 TheClassInstanc e()
ViewState("data ") = cIns.returnSome thing()

'Then again getting it back
...

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

"Max" <ma*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.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*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.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****@aspalli ance.com> ha scritto nel messaggio
news:OG******** ******@TK2MSFTN GP12.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 TheClassInstanc e()
ViewState("data ") = cIns.returnSome thing()

'Then again getting it back
...

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

"Max" <ma*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.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****@aspalli ance.com> ha scritto nel messaggio
news:%2******** ********@TK2MSF TNGP10.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*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.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****@aspalli ance.com> ha scritto nel messaggio
news:OG******** ******@TK2MSFTN GP12.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 TheClassInstanc e()
ViewState("data ") = cIns.returnSome thing()

'Then again getting it back
...

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

"Max" <ma*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.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.Http Context.Current .Session, but there's not similar way to
access ViewState.

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

"Max" <ma*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.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****@aspalli ance.com> ha scritto nel messaggio
news:%2******** ********@TK2MSF TNGP10.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*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.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****@aspalli ance.com> ha scritto nel messaggio
news:OG******** ******@TK2MSFTN GP12.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 TheClassInstanc e()
ViewState("data ") = cIns.returnSome thing()

'Then again getting it back
...

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

"Max" <ma*******@hotm ail.com> wrote in message
news:3a******** *****@individua l.net...
>I need an vb.net class that is invoked from aspx page, that use the
>viewstat e/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
1137
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. ---------------------------------------------------------------------------- ----------------------- Public Class MyWebPage Inherits System.Web.UI.Page
10
2292
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 disable the session state in Web.Config the VIEWSTATE variable is still maintained and stores some values. Can anyone tell what those values are for, i.e what other info is stored in VIEWSTATE other than the session ID and the control values ?
6
4350
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 the controls I get huge delays on postbacks, but if I disable the viewstate I lose all my information. Any sugesstions?
6
1628
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
1381
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 New DataSet I fill the Dataset as follows :
3
4579
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 set textboxes, radio buttons, etc - that viewstate is fine. Then I have a linkbutton that does a Server.Transfer over to Page2.aspx. When I Server.Transfer back to Page1.aspx, the viewstate info is lost. I ran across another example of this last...
7
3552
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 TypeConverter other than ReferenceConverter to be put in viewstate." I've included the <Serializable()> attribute, but I'm still getting the same error. The class is below ... as you can see it contains a Collection, two
15
2424
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 1000 items it might use 100KB. How do I measure the amount of memory used once the class is loaded? Thanks! -- Joe Fallon
6
1613
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 SESSION and that worked. Am I correct in assuming ViewState is cleared on each PageLoad or is my code incorrect. VIEWSTATE If IsNothing(ViewState("PbCounter")) Then
3
1193
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 page) emp.empno=Datareader("empno") - and yes, it does get populated, correctly, at page Load Here's what I need, and isn't working: I have a button on that page, which does a Server.Transfer to another page, using that number, so I do something...
0
10908
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10586
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10293
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7017
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5682
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5866
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4484
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3134
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.