Adding Variable to FormView Textbox


Probably an easy one for you experts............

I've got some code that finds out what the current domain identity/Windoes user is and stores it as a variable.

I'm now trying to display this information in a textbox in a formview but it does not recognise the textbox name  in the code as the textbox is  part of a formview.

What I want to do it add the value of the variable 'authUserName ' to the textbox in the formview called TBMCUserTextBox

I have tried as you can see in that attached code but I just can't get it right.


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim authUserName As String
        Dim aspUserName As String
        Dim DomUser As Control = FindControl("TBMCUserTextBox")
        authUserName = User.Identity.Name
        aspUserName = Principal.WindowsIdentity.GetCurrent.Name
    End Sub

Open in new window

Who is Participating?
TSmoothConnect With a Mentor Commented:
You need to call findcontrol on the formview control itself to find your textbox. I would do that in the FormView's ItemCreated event like so:

Dim DomUser As TextBox = DirectCast(FormView1.FindControl("TBMCUserTextBox"), TextBox)
DomUser.Text = User.Identity.Name

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.