How to store the username of the LoginName Control from the LoginView into a textbox control

StackOverflow https://stackoverflow.com/questions/18175541

  •  24-06-2022
  •  | 
  •  

Domanda

I have a submission form developed in ASP.NET C# and I'm trying to store the username of the LoginName control into a text box control. In simplest terms, make the username display inside a textbox. I'm able to store the current date into a textbox control using the following:

dateCreated.Text = DateTime.Now.ToString();

...with dateCreated being the id of the Textbox control and it works fine.

The following is what I'm attempting to do for the LoginName control:

createdBy.Text = LoginName1.ClientID; 

...with createdBy being the id of the textbox control am attempting to store the username into. The following is the design for my LoginView Control:

<asp:LoginView ID="LoginView1" runat="server">
<AnonymousTemplate>
   You are not Logged in, Click the login link to sign in
</AnonymousTemplate>
<LoggedInTemplate>
   You are Logged in. Welcome, <asp:LoginName ID="LoginName1" runat="server"/>
<LoggedInTemplate>
</asp:LoginView>

but, I'm stuck as to what definition I'm to apply to the LoginName1. Could I please get some help as to how I'm to accomplish this task? I'm new to .Net, Thank You

È stato utile?

Soluzione

You can't capture LoginName content in this way. But the following code will do the job:

createdBy.Text = User.Identity.Name;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top