Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any way to bypass Validating event when closing form?
Message
From
11/02/2008 13:49:49
 
 
To
11/02/2008 12:56:46
John Baird
Coatesville, Pennsylvania, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01291525
Message ID:
01291566
Views:
9
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");
            }
        }
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform