Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Any way to bypass Validating event when closing form?
Message
De
11/02/2008 13:49:49
 
 
À
11/02/2008 12:56:46
John Baird
Coatesville, Pennsylvanie, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Divers
Thread ID:
01291525
Message ID:
01291566
Vues:
8
You don't have to worry about bypassing the validation if you have no handler in place for the action. Go to the properties sheet for the form, then to events, and remove the closing or closed event handler. Then the closing should have no effect on anything.

I do not have an event handler in place, but the closing event does not happen if an invalid entry is in the text box. Here is my validating handler code. Am I doing something stupid here?
private void Validating_Number(object sender, CancelEventArgs e)
        {
            // Cast the sender object as a control
            Control oControl = (Control)sender;

            // try to convert the entry in the textbox
            // to a number

            double nNumber;
            
            try
            {
                if (oControl.Text.Length == 0)
                    oControl.Text = "0";
                else
                    nNumber = Convert.ToDouble(oControl.Text);
            }
            catch
            {
                e.Cancel = true;
                oControl.Select();
                errorProvider1.SetError(oControl, "You must enter a numeric value");
            }
        }
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform