Ver Mensaje Individual
  #2 (permalink)  
Antiguo 13/07/2009, 12:38
skel363
 
Fecha de Ingreso: febrero-2003
Ubicación: chile
Mensajes: 101
Antigüedad: 21 años, 2 meses
Puntos: 1
Respuesta: Validar un campo de texto si es numero o caracter

Tienes que generar algo asi.

Código:
//Funcion para verificar si la cadena ingresada tiene numeros

private bool isNumeric(string txt)
    {
        if (!string.IsNullOrEmpty(txt))
        {
            int num;
            bool isNumeric;
            for (int i = 0; i < txt.Length; i++)
            {
                string c = Convert.ToString(txt[i]);
                isNumeric = int.TryParse(Convert.ToString(txt[i]),out num);
                if (isNumeric)
                    return true;
            }
            return false;
        }
        return false;
    }

//evento click del botón
 protected void Button2_Click(object sender, EventArgs e)
    {
        if (isNumeric(TextBox1.Text.Trim()))
            Label1.Text = "TRAE NUMERO";
        else
            Label1.Text = "NO TRAE NUMERO";
    }
__________________
s[K]eL