在textchanged事件上自定义ASP.NET TextBox

时间:2010-03-10 12:10:32

标签: asp.net vb.net asp.net-ajax

我想让TextBox控制TextChanged事件只在TextBox中有多个字符时才会触发。

谢谢。

2 个答案:

答案 0 :(得分:0)

我认为您需要一个自定义控件,该控件使用自定义事件继承文本框控件,在内部事件中执行检查,并在您认为合适时触发自定义事件。

答案 1 :(得分:0)

Public Class ZTextBox
Inherits System.Windows.Forms.TextBox
Public Event ZTextChanged(ByVal sender As Object, ByVal e As System.EventArgs)

Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    MyBase.OnPaint(e)

    'Add your custom paint code here
End Sub

Private Sub ZTextBox_TextChanged1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.TextChanged
    If Me.Text.Length > 3 Then
        RaiseEvent ZTextChanged(sender, e)
    End If
End Sub End Class

您可以在表单中使用以下内容

    Private Sub ZTextBox1_ZTextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ZTextBox1.ZTextChanged
    MsgBox(1)
End Sub