Solved

Session.Keys to Label.Text

Posted on 2008-10-21
7
1,226 Views
Last Modified: 2012-08-14
I have a Session value Session("Customer")
 How would I write the Session value as a string?

This would be to easy Label1.Text = Session("Customer").ToString();

There are lots of examples of printing out Session.Keys with Response.Write.

But nothing about writing the key as a string.

Thanks for the help,
Ralph
0
Comment
Question by:RalphHxyz
  • 3
  • 3
7 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22773109
you will want to use session.keys only when you want to check all the session key values.
it will normally be used for debugging purposes rather than as a logic

you are correct the way value for session variable is retrieved and shown on the label
Label1.Text = Session["Customer"].ToString();

string keyValues;
foreach(string Key in )ession.Keys
{
       keyValues += "Key:   " & Key;
       keyValues += "Value:   " & Session[Key] + System.Environment.NewLine;
}
Next
0
 

Author Comment

by:RalphHxyz
ID: 22773398
Whoa, Label1.Text = Session["Customer"].ToString(); Does not work!
I was just joking when I used that example.
Apparently I do not want to use Session.Keys ok what do I need to do to make Session
("Customer") a string?
Ralph
0
 
LVL 5

Expert Comment

by:harwantgrewal
ID: 22773410
Hi RalphHxyz

I am confused a bit now I couldn't understand what are you trying to say here?

Harry
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22773418
have you set any value in Session["Customer"]
what kind of object is it - is it a customer object or a string
if its not working then i will assume either the session variable is empty or is containg something else which does not give any output on .ToString()
0
 

Author Comment

by:RalphHxyz
ID: 22775687
Session("Customer") is populated with the Customer's name.
So I would assume it is a string.
If I do a loop with a Response.Write  it is written out.
I do not need "all" of the sessiion keys just Session("Customer").
Ralph
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 500 total points
ID: 22776571
in C# you dont access the session values using Session("Customer")
in order to get them you need to use Session["Customer"].ToString();
Label1.Text = Session["Customer"].ToString();
0
 

Author Comment

by:RalphHxyz
ID: 22779725
Thank you,
I had gessed at:
Label1.Text = Session("Customer").ToString();
but
Label1.Text = Session["Customer"].ToString();
Makes more sense to reference the Session Array.
Thank you.
Ralph
 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
New to SOAP and need some direction 10 46
DateTimepicker 4 33
Syntax Error 2 47
How to have a gridview column with multiple items in a column row. 2 12
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now