We help IT Professionals succeed at work.

Using  "clear" button to set focus to text box

aspirinmornings
on
I have a button called called btnclear
I want to make it so that when i click it it clears all the text fields and sets the focus to my text box called tstFirstName.Text

Thanks for the help i am new as you can see in the code below i am using the easiest way i know how to clear them
txtFirstName.Text = ""
txtLastName.Text = ""
lblNameOutput.Text = ""
txtFirstNum.Text = ""
txtSecondNum.Text = ""
lblNumOutput.Text = ""

Open in new window

Comment
Watch Question

right, you code is good and has no issues, now on the btnclear click just write your code and the end write txtFirstName.setFocus()

txtFirstName.Text = ""
txtLastName.Text = ""
lblNameOutput.Text = ""
txtFirstNum.Text = ""
txtSecondNum.Text = ""
lblNumOutput.Text = ""
txtFirstName.setFocus()

Author

Commented:
when i do that it comes up with a #3 error
it says 'setFocus' is not a member of "system.Windows.Forms.TextBox'.
oh you are using vb.net then use  below line at the end.

txtFirstName.Focus()

Author

Commented:
THANKS!!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.