locked
How to Add UserID to Hidden Text Field. RRS feed

  • Question

  • User-1361977450 posted

     I'm using ASPNetDB.mdb database for membership login and another database to store ads that members submit.

    In my webform that collects the ad info I'd like to populate a field with the logged in member's Name.

     

    Thanks.


         

     

     

     

    Friday, May 7, 2010 5:00 PM

Answers

All replies

  • User1358036820 posted

    <asp:label runat=server text="<%#Membership.GetUser().Name%>" /> 

    Friday, May 7, 2010 10:30 PM
  • User-1199946673 posted

    <asp:label runat=server text="<%#Membership.GetUser().Name%>" /> 

     

    No, waht you mean is:

    Membership.GetUser().UserName

    Although this will work, the GetUser method will make an (Unnecessary) call to the database. A better way to retrieve the username is to use

    User.Identity.Name

    http://msdn.microsoft.com/en-us/library/system.web.httpcontext.user.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 8, 2010 9:57 AM
  • User-1361977450 posted

    Thanks ammd & hans_v !

    This works for me....

     

    <asp:label runat="server" text="<%#Membership.GetUser().UserName%>" />

    Monday, May 10, 2010 8:23 AM
  • User-1199946673 posted

    As I already stated before, this will work, but it will make an unnecessary call to the database. Use User.Identity.Name instead!!!

    But there's another, even easier option. Just drag and drop a LoginName control onto your page... 

    Monday, May 10, 2010 2:45 PM
  • User-1361977450 posted

    Thanks, I'm now using   User.Identity.Name


    Monday, May 10, 2010 2:59 PM