473,698 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Storing Controls as session variables?

is it possible? pros and cons?
Nov 23 '05 #1
12 4967
Don't forget that, if your clients browser disables cookies in his computer,
session will not be used by him.

"Alex D." <al********@hot mail.com> wrote in message
news:uy******** ******@TK2MSFTN GP14.phx.gbl...
is it possible? pros and cons?

Nov 23 '05 #2
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:uy******** ******@TK2MSFTN GP14.phx.gbl...
is it possible? pros and cons?

Nov 23 '05 #3
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadca fe.com> wrote in message
news:e3******** ******@TK2MSFTN GP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:uy******** ******@TK2MSFTN GP14.phx.gbl...
is it possible? pros and cons?


Nov 23 '05 #4
The answer is both yes, and no. Yes you can store any object you want in
sessions, including control instances. But, upon return trips, the instance
you have in session will no longer map to the instance built when ASP.NET
constructs the object model, therefore, any changes made to the object in
session will not be reflected in the page output. The object model is
rebulit on each request.

"Alex D." <al********@hot mail.com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadca fe.com> wrote in message
news:e3******** ******@TK2MSFTN GP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:uy******** ******@TK2MSFTN GP14.phx.gbl...
is it possible? pros and cons?



Nov 23 '05 #5
but instead...the other way around any changes in the original control will
be reflected in the session object?? uhmmm
"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The answer is both yes, and no. Yes you can store any object you want in
sessions, including control instances. But, upon return trips, the
instance you have in session will no longer map to the instance built when
ASP.NET constructs the object model, therefore, any changes made to the
object in session will not be reflected in the page output. The object
model is rebulit on each request.

"Alex D." <al********@hot mail.com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadca fe.com> wrote in message
news:e3******** ******@TK2MSFTN GP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:uy******** ******@TK2MSFTN GP14.phx.gbl...
is it possible? pros and cons?



Nov 23 '05 #6
Obviously not if they do not reference the same object.

It might be something like the following example:

string strA = "hello world!";
string strB = strA;

//
// The two variables refer to the same object just as if you put a control
in the session.
//

strB = null;
strB = "hello world!";

//
// Just as with a page request, strB above is reset and although contains
the same content, they
// are two different objets in memory.
//

I would imaging the same thing happens with the object model. Changes made
in either are not seen by the other.
"Alex D." <al********@hot mail.com> wrote in message
news:OJ******** *****@TK2MSFTNG P10.phx.gbl...
but instead...the other way around any changes in the original control
will be reflected in the session object?? uhmmm
"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The answer is both yes, and no. Yes you can store any object you want in
sessions, including control instances. But, upon return trips, the
instance you have in session will no longer map to the instance built
when ASP.NET constructs the object model, therefore, any changes made to
the object in session will not be reflected in the page output. The
object model is rebulit on each request.

"Alex D." <al********@hot mail.com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadca fe.com> wrote in message
news:e3******** ******@TK2MSFTN GP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:uy******** ******@TK2MSFTN GP14.phx.gbl...
> is it possible? pros and cons?
>



Nov 23 '05 #7
No. Why would you want to store the entire control
in session? I can think of several negatives. What
would be the positive?

That said...

You'd have to research whether the controls
you are saving to session are serializable. If not,
you could never deploy your site in a web farm or
use anything but InProc on a single server.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadca fe.com> wrote in message
news:e3******** ******@TK2MSFTN GP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:uy******** ******@TK2MSFTN GP14.phx.gbl...
is it possible? pros and cons?



Nov 23 '05 #8
may be your example using strings is not the most appropriate in this case
because strings I think are considered a basic type so it is a value type
and not a reference.
and what it seems to me is that reference types are stored as references in
session variables, but instead of that what I needed was to save it as a
value type so I would be a different object.

"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:Oz******** ******@tk2msftn gp13.phx.gbl...
Obviously not if they do not reference the same object.

It might be something like the following example:

string strA = "hello world!";
string strB = strA;

//
// The two variables refer to the same object just as if you put a control
in the session.
//

strB = null;
strB = "hello world!";

//
// Just as with a page request, strB above is reset and although contains
the same content, they
// are two different objets in memory.
//

I would imaging the same thing happens with the object model. Changes
made in either are not seen by the other.
"Alex D." <al********@hot mail.com> wrote in message
news:OJ******** *****@TK2MSFTNG P10.phx.gbl...
but instead...the other way around any changes in the original control
will be reflected in the session object?? uhmmm
"Peter Rilling" <pe***@nospam.r illing.net> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
The answer is both yes, and no. Yes you can store any object you want
in sessions, including control instances. But, upon return trips, the
instance you have in session will no longer map to the instance built
when ASP.NET constructs the object model, therefore, any changes made to
the object in session will not be reflected in the page output. The
object model is rebulit on each request.

"Alex D." <al********@hot mail.com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadca fe.com> wrote in message
news:e3******** ******@TK2MSFTN GP11.phx.gbl...
> Why would you ever want to do this? I could see
> storing the data used to populate the control
> by why the entire control itself? Tons more
> overhead with no additional benefit...
>
> --
> Robbe Morris - 2004/2005 Microsoft MVP C#
> http://www.masterado.net
>
>
>
>
>
> "Alex D." <al********@hot mail.com> wrote in message
> news:uy******** ******@TK2MSFTN GP14.phx.gbl...
>> is it possible? pros and cons?
>>
>
>



Nov 23 '05 #9
a simple use for a TreeView in a session variable is to keep the
collapsed/expanded info for every node when in the postback you redraw the
entire tree and loose all the properties...th en you can restore this values
very easily in each postback. so your tree "remember" which nodes where
collapsed and which expanded...
of course there are many ways of doing this...actually I already used a
different approach...but in the session variable didnt work because just
after repopulating the tree also the session stored tree was affected and
all info erased.

"Robbe Morris [C# MVP]" <in**@eggheadca fe.com> wrote in message
news:%2******** *******@TK2MSFT NGP10.phx.gbl.. .
No. Why would you want to store the entire control
in session? I can think of several negatives. What
would be the positive?

That said...

You'd have to research whether the controls
you are saving to session are serializable. If not,
you could never deploy your site in a web farm or
use anything but InProc on a single server.

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:u6******** ******@TK2MSFTN GP10.phx.gbl...
so..your answer is? yes or no?

"Robbe Morris [C# MVP]" <in**@eggheadca fe.com> wrote in message
news:e3******** ******@TK2MSFTN GP11.phx.gbl...
Why would you ever want to do this? I could see
storing the data used to populate the control
by why the entire control itself? Tons more
overhead with no additional benefit...

--
Robbe Morris - 2004/2005 Microsoft MVP C#
http://www.masterado.net

"Alex D." <al********@hot mail.com> wrote in message
news:uy******** ******@TK2MSFTN GP14.phx.gbl...
is it possible? pros and cons?



Nov 23 '05 #10

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

Similar topics

2
1737
by: Jax | last post by:
Say for example a user of my website makes a selection on the site and I want to store that value for use on a later page what is the best way to do that? My only method at the moment that I know would be to create a static class and static variables inside of that. But if more then one person was using the page would they be using the same variables? Or do they get a version of the static class each? I dont know, which is why I ask. jax
3
1448
by: yop | last post by:
Hello I have an application, Login page, enter UserName & Password. Function in Users called GetUserDetails and checks the details and if they are valid calls a function to fill the following in the class component called Public Class UserDetails Public UserID As Integer
7
1545
by: py | last post by:
how feasible is it to cache an entire page's content in a session variable? i am already doing it and it works fine, except i am afraid of scalability issues. what is the best way to test this? and is there an obvious reason why i should not do this.
3
1200
by: foldface | last post by:
Hi I have the problem at the moment that I have to build a page with all its dynamic buttons etc in order to get postbacks on those buttons, then rebuild the control tree in response to any possible postback. What if I just stored the complete Control tree structure in the session? Alternatively any better ways of doing this? I have tried it on a simple page with 4 buttons and it worked fine, e.g. something like this:
2
1704
by: Curt tabor | last post by:
Hi, I have several pages in my app that all use the same oleDBConnection(s). When this connection gets created, I store it as a Session variable so that other pages can access it w/o having recreate new connections every time they load. I noticed during development that when ever the app first started, the connection would not be in Session when I navigvated to a page that used it. But with subsequent calls everything would be fine and...
0
1036
by: ben | last post by:
I am having some difficulty in understanding how to deal with variables, session states, objects, user controls while attempting to develop a ASP.Net application. I have created several user controls which consist of dropdown and textbox controls on a panel. In order for one user control to access a control on another usercontrol, I have to change the WithEvents to "Protected Shared". That will allow a sub to access a control on a...
9
7294
by: david | last post by:
I have a class with some business-logic and with every roundtrip, I need an instance of this class, so I have to create it, every time again. That doesn't seem very efficient. I thought it would be 'better' to store an instance of this class in a session-variable, so it's available all the time and needs to be instanced only once. Is this, generally speaking, a good idea, storing objects in session-variables ? Do you guys ever use this...
4
12591
by: =?Utf-8?B?YmFzdWxhc3o=?= | last post by:
Hi; I want to store a datatable (or an arraylist) as a session variable but when I try; Session = al_RecNo; I get an error that; "Cannot implicitly convert type 'System.Collections.ArrayList' to 'string'"
6
17133
by: J055 | last post by:
Hi I have the following code. I upload an XML file using the FileUpload object, store the stream in a session so the user gets the chance to confirm some options then pass the stream from the Session to an XmlReader. if (performImport == false) { Session = fileUpload1.FileContent; //... some other code
0
8601
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9021
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...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8860
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...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
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
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3043
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
2327
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.