PC Review


Reply
Thread Tools Rate Thread

Class That use ViewState/session

 
 
Max
Guest
Posts: n/a
 
      24th Mar 2005
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      24th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>



 
Reply With Quote
 
Usenet User
Guest
Posts: n/a
 
      24th Mar 2005
On Thu, 24 Mar 2005 19:19:12 +0100, "Max" <(E-Mail Removed)>
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
....
 
Reply With Quote
 
Max
Guest
Posts: n/a
 
      25th Mar 2005
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" <(E-Mail Removed)> ha scritto nel messaggio
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>>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
>>

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      25th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> ha scritto nel messaggio
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>>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
>>>

>>
>>

>
>



 
Reply With Quote
 
Max
Guest
Posts: n/a
 
      25th Mar 2005
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" <(E-Mail Removed)> ha scritto nel messaggio
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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" <(E-Mail Removed)> ha scritto nel messaggio
>> news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> wrote in message
>>> news:(E-Mail Removed)...
>>>>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
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      25th Mar 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> ha scritto nel messaggio
> news:%(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> 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" <(E-Mail Removed)> ha scritto nel messaggio
>>> news:(E-Mail Removed)...
>>>> 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" <(E-Mail Removed)> wrote in message
>>>> news:(E-Mail Removed)...
>>>>>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
>>>>>
>>>>
>>>>
>>>
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ViewState VS Session dotComPaJi Microsoft C# .NET 2 5th Sep 2007 03:40 PM
ViewState V/s. Session? Arpan Microsoft ASP .NET 1 26th Jul 2006 02:24 AM
ViewState vs Session =?Utf-8?B?VmlzaHdhbmF0aGFuIFJhbWFu?= Microsoft ASP .NET 28 24th Jun 2005 06:07 PM
Class That use ViewState/session Max Microsoft ASP .NET 6 25th Mar 2005 09:26 AM
Viewstate in Session MattC Microsoft ASP .NET 3 26th Jan 2005 09:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:21 AM.