Solved

Session.Keys to Label.Text

Posted on 2008-10-21
7
1,235 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

822 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