Jack T
Jack T

Reputation: 41

TextChanged event doesn't work.

I have a textbox in Form and i want to detect when the text has changed but the code I have found is giving me no joy.

I am probably missing something in the proporties or something you have to define before.

Here is my code:

private void tbxparkingTimesS1_TextChanged(Object sender, EventArgs e)
{
     MessageBox.Show("You are in the ToolStripItem.TextChanged event.");
}

Thanks for any help with this trivial problem.

Upvotes: 1

Views: 9473

Answers (3)

Damith
Damith

Reputation: 63065

Double Click on Text box it will generate text change event for you.

    private void tbxparkingTimesS1_TextChanged(object sender, EventArgs e)
    {
        // implement your code here. 
    }

When you double click VS will create event handler in your designer.cs file as bellow

 this.tbxparkingTimesS1.TextChanged += new System.EventHandler(this.tbxparkingTimesS1_TextChanged);

You can do the same by using property window events or create event on code behind.

Upvotes: 0

Steve
Steve

Reputation: 216243

To wire the TextChanged event to a particular method inside your code do the following

  • Click on the TextBox inside your form
  • Open the properties windows (press F4 or menu View -> Property Window )
  • Select the event page (lightning icon)
  • Double click on the TextChanged property line
  • Insert your code inside the template build for you by Visual Studio

Upvotes: 2

Dave Bish
Dave Bish

Reputation: 19646

Have you assigned the event handler to the textbox?

Normally this will be done "behind the scenes" by Visual Studio - with the result being an additional line of code in your .designer file.

Something like:

this.tbxparkingTimesS1.TextChanged += new System.EventHandler(tbxparkingTimesS1_TextChanged);

(It['s been a while since I've done webforms - so that might be slightly off)

Upvotes: 1

Related Questions