Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
i want show my current username inside the other forms....eg:-show user name every forms using label
Posted 31-Dec-12 21:22pm
Comments
Zoltán Zörgő at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Comments
prashant patil 4987 at 1-Jan-13 3:39am
   
+5
Turbo_23 at 1-Jan-13 8:01am
   
Great, *****
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!
Smile | :)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

If WebForm ,
 
a) Inherit master page, in master page use following controls.
 
In master page
<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."
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 330
1 Sergey Alexandrovich Kryukov 295
2 ClimerChinna 207
3 Magic Wonder 205
4 Gihan Liyanage 192
0 Sergey Alexandrovich Kryukov 8,188
1 OriginalGriff 6,991
2 CPallini 2,598
3 Richard MacCutchan 1,925
4 Abhinav S 1,736


Advertise | Privacy | Mobile
Web01 | 2.8.140826.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
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