Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Comments
Richard MacCutchan 27-Jan-13 11:27am    
This can be achieved by standard string concatenation.

Try:
C#
Session["username"] = firstName + " " + lastName;
...
myLabel.Text = string.Format("Hi, {0}", Session["username"]);
 
Share this answer
 
Comments
ridoy 27-Jan-13 13:19pm    
+5
AshishChaudha 27-Jan-13 23:18pm    
my +5
Renju Vinod 28-Jan-13 0:58am    
+5
try this
C#
Session["username"] = s3 = string.Format("{0} {1}", firstname, lastname);
Label1.Text = Session["username"];

Thanks
 
Share this answer
 
HI,

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

C#
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
 
Share this answer
 
Comments
AshishChaudha 27-Jan-13 23:19pm    
my 5+
[no name] 28-Jan-13 1:29am    
Thanks Ashish...
Hello,

Might be it's helpful...

C#
Session["username"] = "Hi!!" + firstname + lastname ;
Label1.Text = convert.tostring(Session["username"]);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900