473,473 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

context.items collection or session variables

Which is better when passing values between forms?
Nov 19 '05 #1
6 3833
Your question is vague. "Passing values between form"? Do you mean between
postback? From one page to another?

If you mean between postback, viewstate is your best option (depending on
how much data), if you mean between pages, session/querystring/cookie is
your best bet.
check out http://openmymind.net/DataStorage/index.html for more information.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Roman" <sp**@spam.de> wrote in message news:cp*********@online.de...
Which is better when passing values between forms?

Nov 19 '05 #2
Thanks for your reply Karl. I meant between different pages. I need to
pass the key field from a datalist (master) to another page, on button
click, and use it to generate the 'detail' part based on the key. I have
this voice in my head going back to my classic ASP days saying "session
variables are evil, only use them as a last resort". Is this still
applicable with ASP.NET?

I used to be quite fond of using hidden form fields to pass values between
pages on form submission, but that seems much harder to do with web controls
as opposed to HTML input boxes. ie the textbox webcontrol does not have a
'hidden' property.

Your question is vague. "Passing values between form"? Do you mean
between
postback? From one page to another?

If you mean between postback, viewstate is your best option (depending on
how much data), if you mean between pages, session/querystring/cookie is
your best bet.
check out http://openmymind.net/DataStorage/index.html for more
information.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Roman" <sp**@spam.de> wrote in message news:cp*********@online.de...
Which is better when passing values between forms?


Nov 19 '05 #3
Roman,
Both has their advantages and disadvantages. And you can use both
depending on your scenario. Context.Items, correspond to a single http
request, so if you are navigating from one page to another using
Response.Redirect, you can not use Context.Items. Since Response.Redirect
involves two http requests. However, if you choose to use Server.Transfer,
which consists of one single HTTP request, you could use Context.Items. So,
as I said, Context is only for a single http request. So, you can not reuse
the Context items bag in other pages later. So, this does not involve any
memory in your worker process application domain memory.

Where as Session, though it is stored in the application domain's memory, it
can be reused through out your application, which can span multiple http
requests. Session can be stored in the database too, if you would like to.
Though session can eat up your memory if not used properly, it can be used
among multiple pages and multiple requests

So, it all depends on your situation and how you want to use it

Hope I made sense with my explanation. Let me know if you have more
questions
--
Kumar Reddi
http://kumarreddi.blogspot.com

"Roman" <sp**@spam.de> wrote in message news:cp*********@online.de...
Which is better when passing values between forms?

Nov 19 '05 #4
My personal opinion is that session variables are not at all evil in
ASP.Net...but I'll try to give you a more balanced answer.

The problem with session variables (in classic ASP) is that they are stored
directly in the processes memory. If you abuse them by putting large
objects, you'll run into problems. In ASP.Net, sessions are also stored in
memory (by default) but can also be stored out of memory (state server or
SQL Server). This new flexability allows sessions to scale better, be used
in web-farms, not be dependent on a single machine and every other goodie
that you'd expect. As always though, abusing session variables will cause
problems.

You have a huge array of possibilities at your disposal. Sessions,
querystring, cookie. You could also change your architecture an use
postback which opens more options. I think the idea I like the most is to
use server.Transfer to go to your details page, and use Context.Item to
store your values. Context.ITem survives a Server.Transfer but not a
Response.Redirect...check it out :)

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Roman" <sp**@spam.de> wrote in message news:cp**********@online.de...
Thanks for your reply Karl. I meant between different pages. I need to
pass the key field from a datalist (master) to another page, on button
click, and use it to generate the 'detail' part based on the key. I have
this voice in my head going back to my classic ASP days saying "session
variables are evil, only use them as a last resort". Is this still
applicable with ASP.NET?

I used to be quite fond of using hidden form fields to pass values between
pages on form submission, but that seems much harder to do with web controls as opposed to HTML input boxes. ie the textbox webcontrol does not have a
'hidden' property.

Your question is vague. "Passing values between form"? Do you mean
between
postback? From one page to another?

If you mean between postback, viewstate is your best option (depending on how much data), if you mean between pages, session/querystring/cookie is
your best bet.
check out http://openmymind.net/DataStorage/index.html for more
information.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Roman" <sp**@spam.de> wrote in message news:cp*********@online.de...
Which is better when passing values between forms?



Nov 19 '05 #5

Just what I was looking for. Thanks
Roman,
Both has their advantages and disadvantages. And you can use both
depending on your scenario. Context.Items, correspond to a single http
request, so if you are navigating from one page to another using
Response.Redirect, you can not use Context.Items. Since Response.Redirect
involves two http requests. However, if you choose to use Server.Transfer,
which consists of one single HTTP request, you could use Context.Items.
So,
as I said, Context is only for a single http request. So, you can not
reuse
the Context items bag in other pages later. So, this does not involve any
memory in your worker process application domain memory.

Where as Session, though it is stored in the application domain's memory,
it
can be reused through out your application, which can span multiple http
requests. Session can be stored in the database too, if you would like to.
Though session can eat up your memory if not used properly, it can be used
among multiple pages and multiple requests

So, it all depends on your situation and how you want to use it

Hope I made sense with my explanation. Let me know if you have more
questions
--
Kumar Reddi
http://kumarreddi.blogspot.com

"Roman" <sp**@spam.de> wrote in message news:cp*********@online.de...
Which is better when passing values between forms?


Nov 19 '05 #6
I think the idea I like the most is to
use server.Transfer to go to your details page, and use Context.Item to
store your values. Context.ITem survives a Server.Transfer but not a
Response.Redirect...check it out :)

karl


That's what I think i'll be doing. thanks
Nov 19 '05 #7

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

Similar topics

2
by: VS_NET_DEV | last post by:
Hi All, There two ways of passing values between pages - 1) Context.Items.Add 2) Context.Handler (cast the page1 class etc) I know for sure #2 does not store the values between requests. How...
2
by: Rea Peleg | last post by:
Hi eb I am adding in webForm1.aspx some item to the context items collection in order to extract it in the next aspx page: In webForm1.aspx - c# code behind - i do:...
7
by: Mike | last post by:
Hi, I have an ASP.NET solution in which I need to store some information, such as DB user and password. So far, I have used the Context object to share information between the various pages, but I...
2
by: dave | last post by:
This little problem is driving me nuts!! On my webform page I create 2 variables.. Protected p_dml As String = "I" Public Const mwv_id As Integer = 0 ' originally had mwv_id as Protected
3
by: Siobhan | last post by:
I am getting the following error: Run-time exception thrown : System.Web.HttpException - Session state can only be used when enableSessionState is set to true, either in a configuration file or in...
8
by: Steph | last post by:
Hi, Is it better to use the URL method to send informations to a page, or to use the context method ? Thanks.
4
by: nicholas | last post by:
I'm using context to transfer variables from 1 page to another. But, with more than 2 pages it fails. Ex: page1.aspx: Context.Items.Add("customername", customername.text)...
1
by: Hugo Flores | last post by:
Hi, I'm trying to pass information between pages. I'm trying to avoid using QueryString and Session variables. I saw somewhere that I could use contxt.Items.Add (combined with Server.Transfer)...
2
by: Ray Booysen | last post by:
Hi all I have a question. I have a library in my webapp (1.1) that requires access to certain application cache and session variables. At the moment, I have been passing these in as parameters...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
0
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...
1
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...
0
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...
0
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 ...
0
muto222
php
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.