Link to home
Start Free TrialLog in
Avatar of TSFLLC
TSFLLC

asked on

How to update textbox value using global string variable as textbox name

I would normally use the following line of code to update the value of a date textbox in a form.......

SpecificForm.DateTextBox.Text = Format(MonthCalendar1.SelectionStart, "MM/dd/yyyy").ToString

BUT, in this particular sub routine I need to be able to update various maskedtextboxes as shown above using a global variable that has the name of the textbox stored in it.  Using a select case I'm able to identify the form that contains the date field, but I need to be able to use the global variable in updating the textbox because there are multiple date fields on various forms....as opposed to one date field.

How can I replace "DateTextBox" with the global variable to accomplish the task?
Avatar of bigdaddyz99
bigdaddyz99
Flag of United States of America image

You should be able to access the control  by using the form and "finding" the control by name.

dim tbname as string = "mytextbox"

Dim tb As TextBox = CType(Me.FindControl(tbname), TextBox)
tb.Text = "mytext"
Avatar of TSFLLC
TSFLLC

ASKER

I see FindForm in the list but I do not see FindControl.

I'm using VB2005 and Framework 2.0.
ASKER CERTIFIED SOLUTION
Avatar of bigdaddyz99
bigdaddyz99
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TSFLLC

ASKER

I already had a similar function set up on most if not all of my forms when it came to a textbox.....only with this one I needed to add new functions on about ten forms for MaskedTextBox 's.

And after doing that, the procedure worked like a charm.

Thanks! for the effort.