Export (0) Print
Expand All

TextBox.OnTextChanged Method

Raises the TextChanged event. This allows you to handle the event directly.

[Visual Basic]
Protected Overridable Sub OnTextChanged( _
   ByVal e As EventArgs _
)
[C#]
protected virtual void OnTextChanged(
 EventArgs e
);
[C++]
protected: virtual void OnTextChanged(
 EventArgs* e
);
[JScript]
protected function OnTextChanged(
   e : EventArgs
);

Parameters

e
A System.EventArgs that contains event information.

Remarks

The TextChanged event is raised when the content of the text box changes between posts to the server.

Note   A TextBox control must persist some values between posts to the server for this event to work correctly. Be sure that view state is enabled for this control.

Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.

The OnTextChanged method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.

Notes to Inheritors:  When overriding OnTextChanged in a derived class, be sure to call the base class's OnTextChanged method so that registered delegates receive the event.

Example

[Visual Basic] 
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<HTML>
    <HEAD>
        <title>Custom TextBox - OnTextChanged - VB.NET Example</title>
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom TextBox - OnTextChanged - VB.NET Example</h3>
            
            <aspSample:CustomTextBoxOnTextChanged id="TextBox1" autopostback=true
             runat="server">Hello World!</aspSample:CustomTextBoxOnTextChanged>
        </form>
    </body>
</HTML>

[C#] 
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<HTML>
    <HEAD>
        <title>Custom TextBox - OnTextChanged - C# Example</title>
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            <h3>Custom TextBox - OnTextChanged - C# Example</h3>
            
            <aspSample:CustomTextBoxOnTextChanged 
              id="TextBox1" 
              autopostback=true
              runat="server">Hello World!
            </aspSample:CustomTextBoxOnTextChanged>
            
        </form>
    </body>
</HTML>

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

TextBox Class | TextBox Members | System.Web.UI.WebControls Namespace | TextChanged | Raising an Event | Consuming Events | System.EventArgs

Show:
© 2014 Microsoft