Click here to Skip to main content
15,889,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Friends,

I am developing a small application in Visual studio 2010 C#4.0 which has two forms. first is Login form and second login and one is main form.

I need to get the login user name in main form as we see in any websites.

I am trying t get help from anywhere but not succeed yet.

Please help me with this issue.

Thanks in advance.

Ashok Karale
Posted
Comments
Jameel VM 4-Oct-13 10:30am    
please post the code what you have tried

 
Share this answer
 
Comments
abey e mathews 4-Oct-13 11:01am    
session is used to transfer the name to next page..
 
Share this answer
 
Comments
abey e mathews 4-Oct-13 11:02am    
I think.. this login form will works..
ridoy 4-Oct-13 13:02pm    
Are there exactly any reasons to post 2 answers for the same question?!
Probably best solution would be to create a common class and read the value from there as you may need that value on multiple forms when you have.Do something like:
C#
public static class CommonClass
{
  public String LoginUserName {get;set;}
}

Then from Login page set the value by:
C#
CommonClass.LoginUserName = "LoginUserName"; //Use the value you want to pass here

Then from 2nd form(or anywhere) grab that value like:
C#
UserNameLabel.Text = CommonClass.LoginUserName;

Simple,Isn't it?
 
Share this answer
 
Thank you for suggestions but I am again confirming that I am developing desktop application.

Here is my code:

Login page

C#
public static class CommonClass
{
    public string LoginUserName { get; set; }
}
private void Loginbtn_Click(object sender, EventArgs e)
{
    CommonClass.LoginUserName = UserNameTxt.Text;
}


Here CommonClass.LoginUserName = UserNameTxt.Text; showing error.

And in main page Main_Load() our CommonClass is not showing.

Please advise.
 
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