Click here to Skip to main content
11,711,750 members (80,910 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
how to concat first name and last name and display in label in asp.net C#
-------------------------------------------------------------------------


hi friends my project is based on asp.net c#.

while registering to this website user will enter his first name and last name in Registration form.

I want to store this in session.
like session["username"]

so this will display with label like

Hi, Ubaid Rahman


Please help thank u.
Posted 27-Jan-13 5:12am
Comments
Richard MacCutchan at 27-Jan-13 11:27am
   
This can be achieved by standard string concatenation.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try:
Session["username"] = firstName + " " + lastName;
...
myLabel.Text = string.Format("Hi, {0}", Session["username"]);
  Permalink  
Comments
ridoy at 27-Jan-13 13:19pm
   
+5
AshishChaudha at 27-Jan-13 23:18pm
   
my +5
Renju Vinod at 28-Jan-13 0:58am
   
+5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

try this
Session["username"] = s3 = string.Format("{0} {1}", firstname, lastname);
Label1.Text = Session["username"];
Thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

HI,

As mentioned in the above solution you can concatenate and there is another way to concatenate also.

Session["username"] = string.Concat(firstName , lastName);
myLabel.Text = Session["username"];

For reference follow the following link:
C# string.Concat
What's the best string concatenation method using C#?

Thanks
  Permalink  
Comments
AshishChaudha at 27-Jan-13 23:19pm
   
my 5+
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

Hello,

Might be it's helpful...

Session["username"] = "Hi!!" + firstname + lastname ;
Label1.Text = convert.tostring(Session["username"]);
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 CHill60 280
1 Sergey Alexandrovich Kryukov 264
2 OriginalGriff 170
3 Andy Lanng 160
4 Richard MacCutchan 130
0 CHill60 280
1 Sergey Alexandrovich Kryukov 125
2 Andy Lanng 120
3 Abhinav S 95
4 Maciej Los 95


Advertise | Privacy | Mobile
Web01 | 2.8.150819.1 | Last Updated 29 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100