-2

Is this possible? I have a button with onClick() Method. If i click the Button i want to simulate a mouse click event inside a TextBox. With Focus() i can focus inside the TextBox but how to simulate left mouse click?

EDIT I have an AutoCompleteExtender that should show a list of names in a certain TextBox after the user clicks a Button. The TextBox can work both:the user writes a character and the list appears or he clicks the button and a whole list appears.

EDIT I have used AjaxControlToolkit and from my experience i have to click on the TextBox if i want the list to appear even though i have a focis on the TextBox and MinimumPrefixLength=0

Georg
  • 117
  • 3
  • 18

1 Answers1

2

Create a "logic" method where you do your work. When the user clicks on the TextBox, call your logic method. When you want to simulate a click, call your logic method also.

// Attach to the event
myTextBox.Click += new EventHandler(myTextBox_Click);
// Simulate a "click" event
MyLogic();

protected void myTextBox_Click(object o, EventArgs e) {
    MyLogic();
}

private void MyLogic() {
    // Do work
}
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
  • 2
    Spot on with that advice. +1 well deserved. Only point I'd suggest is move MyLogic to anotehr class so it can be independently unit tested. – David Arno Oct 16 '13 at 12:22