Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Validating and Parse problems
Message
 
À
02/04/2004 12:53:34
James Hansen
Canyon Country Consulting
Flagstaff, Arizona, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00891209
Message ID:
00891933
Vues:
34
I agree that the suggestion is not elegant so I hesitated even suggesting it. I hope Bonnie's code will do what you are looking for.

>Thanks for the suggestion, Cathi.
>
>I came across a suggestion along these lines while Googling the dotnet newsgroups, but couldn't figure out quite what it meant: What exception do I throw? Where do I catch it and what do I do with it? Isn't that a kludge that could be broken by a leter release of the framework? Sounds flakey to me.
>
>My goal was to get results something like in VFP where, when a user enters a typo resulting in an invalid entry, an error message is displayed, the input is highlighted and the user can correct it. That is what I naively thought setting Cancel in the Validating event handler would do.
>
>After wasting yet another day trying obtain this behavior, I believe that is not possible. I had a nice solution involving setting a flag in the Validating event handler and saving the text, then restoring the text in the Format event handler, but that didn't work either because the firing of events changes if I don't actually type something in the textbox after restoring the text. (Parse and Format don't fire, only Validating, but that is another story.)
>
>I have reluctantly come to the conclusion it is not practical (and perhaps not possible) to obtain the behavior I desire. I really shouldn't try too hard to buck dotNet's way of doing WinForm input. All it will do is frustrate me and leave me vulnerable to changes in later releases of the framework.
>
>The default dotNet behavior for a textbox bound to a numeric value is to quietly discard typos and to restore the previous contents of the textbox. I find this a very annoying "feature", however. When doing "head down" data entry, I would rather alert the users that they screwed up and let them correct it.
>
>I guess I'll just have to alert the user to the error, then let dotNet wipe out the input. The only other option I can think of is to give up on data binding altogether, but that would be a giant productivity step backwards.
>
>A side effect of this discovery is that I guess I am going to have to write a Validating event handler for every numeric textbox I create to verify that the entry is a valid number so I can alert the user if the input is in an invalid format.
>
>I think these (mis)behaviors should be fixed in Widbey, but I have zero influence with the development staff.
>
>...Jim
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform