Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Session.Keys to Label.Text

Posted on 2008-10-21
7
Medium Priority
?
1,264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

688 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