Solved

Session.Keys to Label.Text

Posted on 2008-10-21
7
1,217 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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

23 Experts available now in Live!

Get 1:1 Help Now