NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

TextBoxBase TextChanged Event

Occurs when the text within the control is changed by the user or in code.

The following declaration shows the syntax for a method that handles the TextChanged event.

[Visual Basic]
Private Sub TextBoxBaseName_TextChanged( _
   ByVal sender As Object, _
   ByVal e As EventArgs _
)
[C#]
private void TextBoxBaseName_TextChanged(
   object sender,
   EventArgs e
);
[C++]
private: void TextBoxBaseName_TextChanged(
   Object* sender,
   EventArgs* e
);
[JScript]
private TextBoxBaseName_TextChanged(
   sender : Object,
   e : EventArgs
);

Parameters

sender
The source of the event.
e
An EventArgs that contains the event data. The following EventArgs properties provide information specific to this event.
Property Description
ExtendedInfo
Holds a reference to an object that manages the event's state.

Remarks

You can use this event to determine when the user has changed the contents of the control. This feature can be used to determine when a field of text needs to be saved prior to an application closing.

Note   A OnTextChanged event procedure can sometimes cause a <span id="frameworks:cascading_event" class ="gp">cascading event</span>. This occurs when the control's OnTextChanged event alters the control's contents. For example, setting a property in code that determines the control's value, such as the Text property. To prevent a cascading event:

Example [Visual Basic]

The following example uses TextBox, a derived class, to create an event handler for the control's OnTextChanged event. The code within the event handler restricts data to numbers. After text has been entered in the control, the code determines if the text entered is a number. If the text is not a number the code clears the text from the control and a MessageBox is displayed to alert the user that only numbers are accepted. The example assumes that a Boolean variable called Flag and a TextBox control called Text1 are defined outside of this method. This example demonstrates how to use a flag to avoid a cascading event in the System.WinForms.TextBoxBase.TextChanged event.

[Visual Basic]

Private Sub MyTextChangedHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
   'Check the flag to prevent code re-entry. 
   If Flag = False Then
       ' Set the Flag to True to prevent re-entry of the code below.
       Flag = True
       ' Determine if the text of the control is a number.
       If IsNumeric(Edit1.Text) = False Then
           ' Display a message box and clear the contents if not a number.
           MessageBox.Show "The text is not a valid number. Please re-enter"
           ' Clear the contents of the text box to allow re-entry.
           Edit1.Clear
       End If
       ' Reset the flag so other TextChanged events are processed correctly.
       Flag = False
   End If        
End Sub

See Also

TextBoxBase Class | TextBoxBase MembersTopic | System.WinForms Namespace