vb .net validar !!!!

27/04/2006 - 23:50 por Yony Jaramillo | Informe spam
Hola saludos
tengo un problemita nesecito validar en
un textbox que no ingrese el apostrofe < ' > en mi
casilla de texto.
es muy importante le agradeseria mucho

Gracias
Si no ami correo
yony_jaramillo@yahoo.es
 

Leer las respuestas

#1 Alberto Poblacion
28/04/2006 - 08:15 | Informe spam
"Yony Jaramillo" wrote in message
news:%
tengo un problemita nesecito validar en
un textbox que no ingrese el apostrofe < ' > en mi
casilla de texto.



Haz una clase hija de textbox, y utilízala en lugar del textbox original.
Dentro de la clase hija haces un Overrides del OnKeypress y "filtras" los
caracteres no deseados. Te quedará parecido a lo siguiente:

Public Class TextBoxSinComilla
Inherits System.Windows.Forms.TextBox

Public Sub New()
MyBase.New()
InitializeComponent()
End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

Private components As System.ComponentModel.IContainer
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub

Public Overrides Property Text() As String
Get
Return MyBase.Text
End Get
Set(ByVal Value As String)
MyBase.Text = Value.Replace("'","")
End Set
End Property

Protected Overrides Sub OnKeyPress(ByVal e As
System.Windows.Forms.KeyPressEventArgs)
If e.KeyChar="'" Then
e.Handled = True
Else
e.Handled = False
Endif
End Sub
End Class

Preguntas similares