Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textbox problem

Status
Not open for further replies.

dabits

Programmer
Apr 28, 2000
18
US
Okay..here is a weird one:)

I have a textbox which is bound to a dataset and a leave event which changes the textbox.text value. The problem is it is changing in the debugger but goes back to original value on the form???!! Any ideas?

Thanks
 
Where in code are you binding the dataset?

Regards,
NatGreen
 
If you have bound the text box in the page on load event put this around the binding code

if not IsPostBack then
code here
end if
[peace]
 
Thanks guys!

What I'm trying to do is have the textbox display a SQL money field with currency formatting. This has lead to an interesting trip through VB.net binding and event handling. The following is for your info and comment:

When textboxes have databindings, the CausesValidating property is set to true automatically. When this occurs some validating occurs against bound data field type. Thus when you try to enter letters in a textbox bound to a money field, it gives you little red exclamation and rejects input. You can override the CausesValidating in the IDE (set it to false).

Since I wanted to format the textbox on load, etc. I needed to do the formatting in the TextChanged event. Unfortunately, this created problems when in the field and changing the text as this event is also fired on every keystroke. What I wound up doing is to remove the event handler for TextChanged event of textbox when in the Enter event. I restore this event when the Leave and LostFocus events are fired. As ugly as this is, it does seem to work! The only problem is I will get a System.Format.Exception error on bindings when I try to update record but only IF I TRAP FOR IT IN DEBUGGER!!! If I don't ... the data goes through okay??

I'm sure there might be other ways to do this. Perhaps working with a Validating event. A more interesting possibility is to create a custom textbox control with a "shadow" text field used for display. What do you guys think?

Thanks Again
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top