Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2004

Tip: Looking for answers? Try searching our database.

Parse, Format, Validating of Databound TextBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Paul - 06 Oct 2004 18:36 GMT
I have a textbox bound to a custom object property that accepts only
positive percentages as values.  I use a regular expression in the
'Validating' event to check the entered data.  The regex is written such
that the user can enter 0.25 or 25% and the result will be the same.  It
does not allow negative values.

There is also a 'Parse' and 'Format' handler associated with the
databinding.  The Parse converts the entered data into a number and the
format converts it back to a string with the '%' appended.

If the user enters an invalid value (i.e. -5%), the Validating event
seems to work correctly, but the Parse and Format events still trigger
despite setting e.cancel in the validating event.

Ideally, the Parse and Format events would not fire unless the
validating succeeds.

Any ideas on how to handle this?

Thanks.
Sijin Joseph - 07 Oct 2004 04:47 GMT
In the parse and format events what values are being passed incase of
invalid input?..is it the invalid input or the previous valid input?

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> I have a textbox bound to a custom object property that accepts only
> positive percentages as values.  I use a regular expression in the
[quoted text clipped - 16 lines]
>
> Thanks.
Paul - 07 Oct 2004 13:28 GMT
Thank you for the reply.

The invalid input is being passed to the Parse and Format events despite
the validation being cancelled.

For instance, if I enter -5, it will parse and then format it as -500%.
Sijin Joseph - 11 Oct 2004 05:25 GMT
Yup i am able to reproduce the behavior on my system too. Pretty
strange, but there must have been a reason to design the system like
that. It is not a bug, Reflector shows that whenever you do a
EndCurrentEdit() on the control, which happens when you validate the
control, the PropertyManager is going to pulldata from the datasource
causing the format and parse events to fire.

The only workaround is to do the validation again in parse and maybe
reset the value to zero or something or let it be as it is and in the
format event only put percentage values for positie values. ugly i know....

Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph

> Thank you for the reply.
>
> The invalid input is being passed to the Parse and Format events despite
> the validation being cancelled.
>
> For instance, if I enter -5, it will parse and then format it as -500%.
Paul - 12 Oct 2004 23:42 GMT
Thank you for looking into this.  I was afraid that was going to be the
case.  Still not sure why it works like that, but oh well.

Thank you again.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.