By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 1,964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

context.items collection or session variables

P: n/a
Which is better when passing values between forms?
Nov 19 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.