Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 423287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:09:55+00:00 2026-05-12T19:09:55+00:00

How do I get to the current users name without doing it in the

  • 0

How do I get to the current users name without doing it in the code-behind, just using the aspx server tags?

In code-behind I can just do this:

Label4.Text = User.Identity.Name.ToString()

But I’m trying to do it without code-behind like this:

<body>
    <form id="form1" runat="server">
    <div>
        1. <asp:Label ID="Label1" runat="server" Text="<% User.Identity.Name %>"/><br />
        2. <asp:Label ID="Label2" runat="server" Text="<%= User.Identity.Name %>"/><br />
        3. <asp:Label ID="Label3" runat="server" Text="<%# User.Identity.Name %>"/><br />
        4. <asp:Label ID="Label4" runat="server" Text="<%= Context.User.Identity.Name %>"/><br />
        5. <asp:Label ID="Label5" runat="server" Text='<%# User.Identity.Name %>' /><br />
        6. <span runat="server" ID="Span1"><%= User.Identity.Name %></span><br />
        7. <asp:LoginName ID="LoginName1" runat="server" /><br />
        8. <span><%# User.Identity.Name %></span><br />
        9. <span><%= User.Identity.Name %></span><br />
        10. <asp:Label ID="Label6" runat="server" Text='<%= User.Identity.Name %>' /><br />
    </div>
    </form>
</body>

I get the username displayed for lines 6, 7, and 9 but I really want to set a property of a control to this value and not just display it on screen.

Is it possible?

Background: I was whipping up a quick app, dragging and dropping controls on the page, and it turned out that I did it with only having 1 line in code-behind of the page(s). That line was setting the value of a hidden field to the current users name in page load so I could pass the value of that control as a param of a sqlparameter. So I thought that since I was going this route (lots of stuff in aspx that maybe shouldn’t be there) I should try to be consistent with it. I don’t normally do it this way, but wanted to this time

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T19:09:55+00:00Added an answer on May 12, 2026 at 7:09 pm

    In a comment you wrote:

    Also, if I could get any controls
    value set to this username I could
    then specify my sqlparameter is a
    controlparameter and that would get me
    where I need to be too.

    You can create a custom parameter type.

    Start by creating this class, either in App_Code or in a ASP.NET Server control dll:

    namespace ParameterDemo {
        public class LoginParameter : Parameter {
            public LoginParameter(string name)
                : base(name)
            {}
    
            protected override object Evaluate(HttpContext context, Control control)
            {
                //UPDATED as suggested in Joels comments below...
                //return HttpContext.Current.User.Identity.Name;
                return context.Current.User.Identity.Name;
            }
        }
    }
    

    and registering it on the page (right after the @Page directive)

    <%@ Register TagPrefix="put" Namespace="ParameterDemo" %>
    

    (or optionally register it in web.config for use on all pages)

    …and the you can use it like this:

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        SelectCommand="SELECT * FROM MyTable WHERE SomeValue=@SomeParameter">
        <SelectParameters>
            <put:loginParameter name="SomeParameter" />
        </SelectParameters>
    </asp:ObjectDataSource>
    

    If this is what you’re looking for, you should consider editing the original question…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 371k
  • Answers 371k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can easily get the classes via Reflection: var formNames… May 14, 2026 at 7:04 pm
  • Editorial Team
    Editorial Team added an answer After googling more i am able find the solution like… May 14, 2026 at 7:04 pm
  • Editorial Team
    Editorial Team added an answer Opening and retrieving a URL is the output of the… May 14, 2026 at 7:04 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.