从登录表单获取用户名到另一个表单,如主窗体。 [英] Get user name from Login form to another form like main form.

查看:112
本文介绍了从登录表单获取用户名到另一个表单,如主窗体。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我正在Visual Studio 2010 C#4.0中开发一个小应用程序,它有两种形式。首先是登录表单和第二次登录,一个是主表单。



我需要获取主表单中的登录用户名,如我们在任何网站中看到的那样。



我正试图从任何地方获得帮助但尚未成功。



请帮我解决这个问题。



提前致谢。



Ashok Karale

解决方案

如何通过页面asp.net中从一页到另一页的值 [ ^ ]


使用Session创建安全ASP.NET登录的简便方法 [ ^ ]


可能最好的解决方案是创建一个公共类,并从那里读取值,因为你可能需要多个表单上的值。做类似的事情:

  public   static   class  CommonClass 
{
public 字符串 LoginUserName { get ; set ;}
}



然后从登录页面设置值:

< pre lang =c#> CommonClass.LoginUserName = LoginUserName; // 使用您想要传递的值



然后从第二个表格(或任何地方)获取该值,如:

 UserNameLabel.Text = CommonClass.LoginUserName; 



简单,不是吗?


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

解决方案

How to Pass Page Values from one page to another page in asp.net[^]


Easy way to create secure ASP.NET login using Session[^]


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:

public static class CommonClass
{
  public String LoginUserName {get;set;}
}


Then from Login page set the value by:

CommonClass.LoginUserName = "LoginUserName"; //Use the value you want to pass here


Then from 2nd form(or anywhere) grab that value like:

UserNameLabel.Text = CommonClass.LoginUserName;


Simple,Isn't it?


这篇关于从登录表单获取用户名到另一个表单,如主窗体。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆