Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Session.Keys to Label.Text

Posted on 2008-10-21
7
Medium Priority
?
1,269 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

963 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