TextBox.OnTextChanged(EventArgs) 메서드

정의

TextChanged 이벤트를 발생시킵니다. 이렇게 하면 이벤트를 직접 처리할 수 있습니다.

protected:
 virtual void OnTextChanged(EventArgs ^ e);
protected virtual void OnTextChanged (EventArgs e);
abstract member OnTextChanged : EventArgs -> unit
override this.OnTextChanged : EventArgs -> unit
Protected Overridable Sub OnTextChanged (e As EventArgs)

매개 변수

e
EventArgs

이벤트 정보가 들어 있는 EventArgs입니다.

예제

다음 코드 예제를 재정의 OnTextChanged 하는 방법을 보여 줍니다는 메서드를 항상 수정 된 것으로 사용자 지정 TextBox 서버 컨트롤을 표시 합니다.

중요

이 예제에는 사용자 입력을 허용하는 텍스트 상자가 있으므로 보안상 위험할 수 있습니다. 기본적으로 ASP.NET 웹 페이지는 사용자 입력 내용에 스크립트 또는 HTML 요소가 포함되어 있지 않은지 확인합니다. 자세한 내용은 Script Exploits Overview를 참조하세요.

<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS" %>
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <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>
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB" %>
<%@ Page Language="VB" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <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>
using System.Web;
using System.Security.Permissions;

namespace Samples.AspNet.CS.Controls
{
  [AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
  public sealed class CustomTextBoxOnTextChanged : System.Web.UI.WebControls.TextBox
  {
    private bool isDirty = false;

    protected override void OnTextChanged(System.EventArgs e)
    {
      // Call the base OnTextChanged method.
      base.OnTextChanged(e);

      // Change the dirty flag to True.
      isDirty = true;
    }
  }
}
Imports System.Web
Imports System.Security.Permissions

Namespace Samples.AspNet.VB.Controls
    <AspNetHostingPermission(SecurityAction.Demand, Level:=AspNetHostingPermissionLevel.Minimal)> _
    Public NotInheritable Class CustomTextBoxOnTextChanged
        Inherits System.Web.UI.WebControls.TextBox

        Private isDirty As Boolean = False

        Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)

            ' Call the base OnTextChanged method.
            MyBase.OnTextChanged(e)

            ' Change the dirty flag to True.
            isDirty = True
        End Sub
    End Class
End Namespace

설명

TextChanged 이벤트는 텍스트 상자의 내용이 서버에 대한 게시물 간에 변경될 때 발생합니다.

참고

TextBox 이 이벤트가 제대로 작동하려면 컨트롤이 서버에 대한 게시물 간에 일부 값을 유지해야 합니다. 이 컨트롤에 대해 뷰 상태가 사용하도록 설정되어 있는지 확인합니다.

이벤트가 발생하면 대리자를 통해 이벤트 처리기가 호출됩니다. 자세한 내용은 이벤트 처리 및 발생합니다.

또한 OnTextChanged 메서드를 사용하면 파생 클래스가 대리자를 연결하지 않고도 이벤트를 처리할 수 있습니다. 이는 파생 클래스에서 이벤트를 처리하는 기본 방법입니다.

상속자 참고

파생 클래스에서 OnTextChanged(EventArgs)를 재정의하는 경우 등록된 대리자가 이벤트를 받도록 기본 클래스의 OnTextChanged(EventArgs) 메서드를 호출해야 합니다.

적용 대상

추가 정보