Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want show my current username inside the other forms....eg:-show user name every forms using label
Posted
Comments
Zoltán Zörgő 1-Jan-13 3:35am    
And what is the question?
Windows Forms, Web Forms?
Current "username" - what user, Windows user running the application, or you have some authentication and authorization mechanism implemented?
Sergey Alexandrovich Kryukov 1-Jan-13 3:46am    
This is not a question, this is yet another "I want...". If you want something, make it. If you have a problem, ask a question.
—SA

There are a number of ways to do this:

1) You could have a property in each form which is set when it is created (or part of the constructor)
2) You could create a static method in your user class which returns the current logged in user name (or the current logged in user).
3) You could make your user class a singleton, which returns the one-and-only user instance and get the required information from there.

Probably, I would use the second or third method, depending on how the rest of your application works. If you have an Admin mode which accesses multiple users for example, you can't use a singleton pattern for your user.

The first method works well, but it requires you to make sure you pass the into through to each form, and can make it difficult if one form logs out the user - all the other forms may need to be notified.
 
Share this answer
 
Comments
prashant patil 4987 1-Jan-13 3:39am    
+5
[no name] 1-Jan-13 8:01am    
Great, *****
If It is a WinForm
then use MDI Container and show there in a control no need to show in each page.

If It is a WebForm
then use Master page and show there in a control no need to show in each page just inherit master template in your form.

ELSE

create a form and write code on load event to add label control runtime and show username inside
and now, just inherit that form in all forms


Happy Coding!
:)
 
Share this answer
 
If WebForm ,

a) Inherit master page, in master page use following controls.

In master page
XML
<asp:LoginName ID="LoginName1" runat="server" />
                <asp:LoginStatus ID="LoginStatus1" runat="server" />



b) If you are not inheriting master page then set user name in session & in each page get user name from session.

If Windows Application, Check solution posted by "OriginalGriff."
 
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