Assign Logged in User to Textbox inside a FormView Control

38 Views Asked by At

ASP.Net using C# I am in need of correct syntax. This is critical at this point. I need to assign the Authenticated/Logged in user to a Textbox inside a FormView control (FormView1 to be exact)! I can't get this any further and I am asking for help. I want to admit upfront that I don't have a full grasp of this and if you can help please, please provide the correct code. I know what I have is wrong but I'm just showing what I am trying to do so far. I am doing an insert of the Form's data into a database table in SQL Server. Error message: Severity Code Description Project File Line Suppression State Error CS0103 The name 'Submitted_by_email' does not exist in the current context echodevelopment C:\Users\dmartin\source\repos\echodevelopment\echodevelopment\Submitinitialrequest.aspx.cs 30 Active

     protected void FormView1_DataBound(object sender, EventArgs e)
    {
        if (FormView1.CurrentMode == FormViewMode.Insert)
        {
            TextBox TGG = (TextBox)FormView1.FindControl("Submitted_by_email");
            TGG.Text = Submitted_by_email.Text;
        }

        if (submitted_by_email != null)
        {
            _ = Context.User.Identity.Name;
            if (User.Identity.IsAuthenticated)
                submitted_by_email.Text = User.Identity.Name;
        }
    }
1

There are 1 best solutions below

0
On

Solved!

  protected void Page_Load(object sender, EventArgs e)
    {
        TextBox MyTextBox = (TextBox)FormView1.FindControl("TextBoxID");

       MyTextBox.Text = User.Identity.Name;
    }

}

}