473,382 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Session State in C#


I'm fairly new to the c# language.... I want to be able to retrieve info
from page 1 and carry it over page 3,4,5... then finally put into a
database... tell me what's wrong with this simple codes...

source.aspx
protected void Subitrequest_Click(object sender, EventArgs e)
{
Session["name"] = DropDownList8.Text;

}

----------------------------------------------------------
Target.aspx
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["name"];

Response.Write(Label1.Text);
}

What I want to do is extremely simple, retrieve all sort of info from
textboxes and dropdownlists from source.aspx and carry them over to
other pages ....Again I'm using asp.net with C# ....

Thanks G.

--
grecci
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Nov 29 '06 #1
3 1378
Hi,

grecci wrote:
I'm fairly new to the c# language.... I want to be able to retrieve info
from page 1 and carry it over page 3,4,5... then finally put into a
database... tell me what's wrong with this simple codes...

source.aspx
protected void Subitrequest_Click(object sender, EventArgs e)
{
Session["name"] = DropDownList8.Text;

}

----------------------------------------------------------
Target.aspx
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Session["name"];

Response.Write(Label1.Text);
}

What I want to do is extremely simple, retrieve all sort of info from
textboxes and dropdownlists from source.aspx and carry them over to
other pages ....Again I'm using asp.net with C# ....

Thanks G.
There is nothing wrong with your code, but you must check if the Session
variable exists, or else you risk that it is null and throws an
exception when used.

Additionally, using IDs hardcoded is bad practice. Save the IDs (like
"name") as constants in one of the pages, and you can access them from
the other pages.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 29 '06 #2
Hi,

Laurent is right.
Try

if (Session["name"]==null)
Session.Add("name",yourValue);
else
Session["name"]=yourValue;

.....
And its better to use constent string or enum.... as the "key" of the
session state
Masudur
Kaz Software Ltd.
www.kaz.com.bd

Nov 29 '06 #3
Hi,

Masudur wrote:
Hi,

Laurent is right.
Try

if (Session["name"]==null)
Session.Add("name",yourValue);
else
Session["name"]=yourValue;
Unnecessary.

Session[ "name" ] = value;
and
Session.Add( "name", value );

are equivalent.
....
And its better to use constent string or enum.... as the "key" of the
session state
No, the key for the Session object must be a string.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 29 '06 #4

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

Similar topics

5
by: Phil Grimpo | last post by:
I have a very odd situation here. I have an administration page, where based on a users permissions, a recordset is called from the SQL server which has a list of paths to "Module Menus". Each of...
3
by: Nhi Lam | last post by:
Hi, I understand that there are 3 modes in which I can configure the SessionStateModule. What I need is an out of process Session State store with fail over support. The "SQL Server Mode" seems...
2
by: John A Grandy | last post by:
for high traffic public websites , what are the proven options for session-state storage & management ? is an out-of-process state-server generally preferred over a sql-server ? what are the...
1
by: Johan Nedin | last post by:
Hello! I have a problem with SQLSession state on my ASP.NET pages. SQLSession state behaves very different from InProcess session state, which I think is very bad. I can understand some of...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
5
by: Sean | last post by:
Problem with sessions I have created an application without concern for sessions. As it turns out I think that might be my undoing. What I have: I have an online quiz. I don’t need to know...
18
by: BillE | last post by:
When a user opens a new IE browser window using File-New-Window the integrity of an application which relies on session state is COMPLETELY undermined. Anyone who overlooks the fact that...
11
by: Glenn | last post by:
Hi I've been experimenting with managing state using the Session object. I've created a simple WS with a couple of methods, one which sets a string value, another that retrieves it. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.