Adding Variable to FormView Textbox

Hi

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.

Thnaks


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

EdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TSmoothCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.