Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.
I have a code here where the loginname will display the computer name.
I have another textbox,where i want the same loginname value to be displayed in the textbox.

Any ideas on how to do this,guys?

Here's my code :

XML
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:LoginView ID="LoginView1" runat="server">
            <LoggedInTemplate>
                <br />
                <br />
                <br />
                welcome
                <asp:LoginName ID="LoginName1" runat="server"  />//THIS LOGIN NAME TO BE DISPLAYED IN TEXTBOX 2 BELOW
                <br />
                <br />
                <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                    ConnectionString="<%$ ConnectionStrings:ASPNETDBConnectionString %>"
                    SelectCommand="SELECT [ApplicationName], [LoweredApplicationName] FROM [vw_aspnet_Applications]">
                </asp:SqlDataSource>
                <br />
                <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
                    <EditItemTemplate>
                        ApplicationName:
                        <asp:TextBox ID="ApplicationNameTextBox" runat="server"
                            Text='<%# Bind("ApplicationName") %>' />
                        <br />
                        LoweredApplicationName:
                        <asp:TextBox ID="LoweredApplicationNameTextBox" runat="server"
                            Text='<%# Bind("LoweredApplicationName") %>' />
                        <br />
                        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
                            CommandName="Update" Text="Update" />
                        &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
                            CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        ApplicationName:
                        <asp:TextBox ID="ApplicationNameTextBox" runat="server"
                            Text='<%# Bind("ApplicationName") %>' />
                        <br />
                        LoweredApplicationName:
                        <asp:TextBox ID="LoweredApplicationNameTextBox" runat="server"
                            Text='<%# Bind("LoweredApplicationName") %>' />
                        <br />
                        <br />
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        <br />
                        <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
                            CommandName="Insert" Text="Insert" />
                        &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
                            CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                    </InsertItemTemplate>
                    <ItemTemplate>
                        ApplicationName:
                        <asp:Label ID="ApplicationNameLabel" runat="server"
                            Text='<%# Bind("ApplicationName") %>' />
                        <br />
                        LoweredApplicationName:
                        <asp:Label ID="LoweredApplicationNameLabel" runat="server"
                            Text='<%# Bind("LoweredApplicationName") %>' />
                        <br />
                        <asp:TextBox ID="TextBox2" runat="server" ToolTip="TextBox2"></asp:TextBox>//DISPLAY LOGINNAME VALUE ABOVE INTO THISTEXTBOX
                        <br />
                        <br />
                    </ItemTemplate>
                </asp:FormView>
                <br />
            </LoggedInTemplate>
            <AnonymousTemplate>
                please login<br />
                <br />
                <br />
                <asp:Login ID="Login1" runat="server">
                </asp:Login>
                <br />
                <br />
                <br />
            </AnonymousTemplate>
        </asp:LoginView>
    </div>
    </form>
</body>
</html>
Posted

1 solution

Hi,

You can get the Machine name and Logged in User name using following code:
C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //To get the machine name
            txtMachineName.Text = Dns.GetHostName();
            //To get the logged in user name
            System.Security.Principal.WindowsPrincipal p = System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal;
            txtUserName.Text = p.Identity.Name;
        }
    }



Please do let me know, if you have any doubt.

Please provide Vote if this would be helpful to you.

Thanks,
Imdadhusen
 
Share this answer
 
Comments
pwtc222 14-Sep-10 4:01am    
textbox2 above cannot be found because it is in loginview and formview.
your code can only be applied outside the loginview. :-)

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